Neural network unit that interrupts processing core upon condition

ABSTRACT

A method for operating an apparatus that includes a program memory, a data memory and a status register that holds a status, wherein the status has fields including: a program memory address at which a most recent instruction is fetched from the program memory, a data memory access address at which data has most recently been accessed in the data memory by the apparatus and a repeat count indicating a number of times an operation specified in a current program instruction remains to be performed, the apparatus further including a condition register having condition fields corresponding to the status fields held in the status register, the method including: writing the condition register with a condition including the condition fields; and generating an interrupt request to a processing core in response to detecting that the status held in the status register satisfies the condition specified in the condition register.

CROSS REFERENCE TO RELATED APPLICATIONS

The present application is a continuation-in-part of U.S. patentapplication Ser. No. 15/090,665 filed Apr. 5, 2016, which claimspriority to provisional applications: Ser. No. 62/299,191, filed Feb.24, 2016, Ser. No. 62/262,104, filed Dec. 2, 2015, and Ser. No.62/239,254, filed Oct. 8, 2015. The present application is also acontinuation-in-part of U.S. patent application Ser. No. 15/090,701filed Apr. 5, 2016, which claims priority to provisional applications:Ser. No. 62/299,191, filed Feb. 24, 2016, Ser. No. 62/262,104, filedDec. 2, 2015, and Ser. No. 62/239,254, filed Oct. 8, 2015. The presentapplication is also a continuation-in-part of U.S. patent applicationSer. No. 15/090,801 filed Apr. 5, 2016, which claims priority toprovisional applications: Ser. No. 62/299,191, filed Feb. 24, 2016, Ser.No. 62/262,104, filed Dec. 2, 2015, and Ser. No. 62/239,254, filed Oct.8, 2015. The present application is also a continuation-in-part of U.S.patent application Ser. No. 15/366,027 filed Dec. 1, 2016. Finally, thepresent application claims priority to U.S. Provisional Application Ser.No. 62/521,250, filed on Jun. 16, 2017. The entire disclosures of eachof the above-referenced applications are incorporated herein byreference.

This application is related to the following U.S. Non-Provisionalapplications, each of which is hereby incorporated by reference in itsentirety.

Serial No. Filing Date Title 15/090,665 Apr. 5, 2016 NEURAL NETWORK UNITWITH NEURAL MEMORY AND ARRAY OF NEURAL PROCESSING UNITS THATCOLLECTIVELY SHIFT ROW OF DATA RECEIVED FROM NEURAL MEMORY 15/090,666Apr. 5, 2016 TRI-CONFIGURATION NEURAL NETWORK UNIT 15/090,669 Apr. 5,2016 PROCESSOR WITH ARCHITECTURAL NEURAL NETWORK EXECUTION UNIT15/090,672 Apr. 5, 2016 NEURAL NETWORK UNIT WITH NEURAL PROCESSING UNITSDYNAMICALLY CONFIGURABLE TO PROCESS MULTIPLE DATA SIZES 15/090,678 Apr.5, 2016 NEURAL PROCESSING UNIT THAT SELECTIVELY WRITES BACK TO NEURALMEMORY EITHER ACTIVATION FUNCTION OUTPUT OR ACCUMULATOR VALUE 15/090,691Apr. 5, 2016 NEURAL NETWORK UNIT WITH SHARED ACTIVATION FUNCTION UNITS15/090,696 Apr. 5, 2016 NEURAL NETWORK UNIT EMPLOYING USERSUPPLIEDRECIPROCAL FOR NORMALIZING AN ACCUMULATED VALUE 15/090,701 Apr. 5, 2016PROCESSOR WITH VARIABLE RATE EXECUTION UNIT 15/090,705 Apr. 5, 2016MECHANISM FOR COMMUNICATION BETWEEN ARCHITECTURAL PROGRAM RUNNING ONPROCESSOR AND NON-ARCHITECTURAL PROGRAM RUNNING ON EXECUTION UNIT OF THEPROCESSOR REGARDING SHARED RESOURCE 15/090,708 Apr. 5, 2016 DIRECTEXECUTION BY AN EXECUTION UNIT OF A MICRO-OPERATION LOADED INTO ANARCHITECTURAL REGISTER FILE BY AN ARCHITECTURAL INSTRUCTION OF APROCESSOR 15/090,712 Apr. 5, 2016 MULTI-OPERATION NEURAL NETWORK UNIT15/090,722 Apr. 5, 2016 NEURAL NETWORK UNIT THAT PERFORMS CONVOLUTIONSUSING COLLECTIVE SHIFT REGISTER AMONG ARRAY OF NEURAL PROCESSING UNITS15/090,727 Apr. 5, 2016 NEURAL NETWORK UNIT WITH PLURALITY OF SELECTABLEOUTPUT FUNCTIONS 15/090,794 Apr. 5, 2016 NEURAL NETWORK UNIT THATPERFORMS STOCHASTIC ROUNDING 15/090,796 Apr. 5, 2016 APPARATUS EMPLOYINGUSER-SPECIFIED BINARY POINT FIXED POINT ARITHMETIC 15/090,798 Apr. 5,2016 PROCESSOR WITH HYBRID COPROCESSOR/EXECUTION UNIT NEURAL NETWORKUNIT 15/090,801 Apr. 5, 2016 NEURAL NETWORK UNIT WITH OUTPUT BUFFERFEEDBACK AND MASKING CAPABILITY 15/090,807 Apr. 5, 2016 NEURAL NETWORKUNIT THAT PERFORMS CONCURRENT LSTM CELL CALCULATIONS 15/090,814 Apr. 5,2016 NEURAL NETWORK UNIT WITH OUTPUT BUFFER FEEDBACK FOR PERFORMINGRECURRENT NEURAL NETWORK COMPUTATIONS 15/090,823 Apr. 5, 2016 NEURALNETWORK UNIT WITH NEURAL MEMORY AND ARRAY OF NEURAL PROCESSING UNITS ANDSEQUENCER THAT COLLECTIVELY SHIFT ROW OF DATA RECEIVED FROM NEURALMEMORY 15/090,829 Apr. 5, 2016 NEURAL NETWORK UNIT WITH OUTPUT BUFFERFEEDBACK AND MASKING CAPABILITY WITH PROCESSING UNIT GROUPS THAT OPERATEAS RECURRENT NEURAL NETWORK LSTM CELLS

Each of the above Non-Provisional applications claims priority based onthe following U.S. Provisional applications, each of which is herebyincorporated by reference in its entirety.

Serial No. Filing Date Title 62/239,254 Oct. 8, 2015 PROCESSOR WITHNEURAL NETWORK UNIT 62/262,104 Dec. 2, 2015 PROCESSOR WITH VARIABLE RATEEXECUTION UNIT 62/299,191 Feb. 4, 2016 MECHANISM FOR COMMUNICATIONBETWEEN ARCHITECTURAL PROGRAM RUNNING ON PROCESSOR AND NON-ARCHITECTURALPROGRAM RUNNING ON EXECUTION UNIT OF THE PROCESSOR REGARDING SHAREDRESOURCE; NEURAL NETWORK UNIT WITH OUTPUT BUFFER FEEDBACK AND MASKINGCAPABILITY, AND THAT PERFORMS CONCURRENT LSTM CELL CALCULATIONS, ANDWITH OUTPUT BUFFER FEEDBACK FOR PERFORMING RECURRENT NEURAL NETWORKCOMPUTATIONS

This application is also related to the following U.S. Non-Provisionalapplications, each of which is hereby incorporated by reference in itsentirety.

Serial No. Filing Date Title 15/366,027 Dec. 1, 2016 PROCESSOR WITHMEMORY ARRAY OPERABLE AS EITHER CACHE MEMORY OR NEURAL NETWORK UNITMEMORY 15/366,053 Dec. 1, 2016 PROCESSOR WITH MEMORY ARRAY OPERABLE ASEITHER LAST LEVEL CACHE SLICE OR NEURAL NETWORK UNIT MEMORY 15/366,057Dec. 1, 2016 PROCESSOR WITH MEMORY ARRAY OPERABLE AS EITHER VICTIM CACHEOR NEURAL NETWORK UNIT MEMORY 15/366,035 Dec. 1, 2016 NEURAL NETWORKUNIT THAT PERFORMS EFFICIENT 3-DIMENSIONAL CONVOLUTIONS 15/366,041 Dec.1, 2016 NEURAL NETWORK UNIT WITH MEMORY LAYOUT TO PERFORM EFFICIENT3-DIMENSIONAL CONVOLUTIONS 15/366,018 Dec. 1, 2016 NEURAL NETWORK UNITWITH NEURAL MEMORY AND ARRAY OF NEURAL PROCESSING UNITS THATCOLLECTIVELY PERFORM MULTI-WORD DISTANCE ROTATES OF ROW OF DATA RECEIVEDFROM NEURAL MEMORY 15/372,555 Dec. 8, 2016 NEURAL NETWORK UNIT WITHMIXED DATA AND WEIGHT SIZE COMPUTATION CAPABILITY

This application is also related to the following U.S. Non-Provisionalapplications, each of which is hereby incorporated by reference in itsentirety.

Serial No. Filing Date Title 15/396,566 Dec. 31, 2016 NEURAL NETWORKUNIT WITH RE-SHAPEABLE MEMORY 15/396,571 Dec. 31, 2016 NEURAL NETWORKUNIT WITH SEGMENTABLE ARRAY WIDTH ROTATOR 15/396,575 Dec. 31, 2016NEURAL NETWORK UNIT WITH SEGMENTABLE ARRAY WIDTH ROTATOR ANDRE-SHAPEABLE WEIGHT MEMORY TO MATCH SEGMENT WIDTH TO PROVIDE COMMONWEIGHTS TO MULTIPLE ROTATOR SEGMENTS 15/396,577 Dec. 31, 2016 NEURALNETWORK UNIT WITH SEGMENTABLE ARRAY WIDTH ROTATOR

BACKGROUND Technical Field

The disclosure relates to a method for operating an apparatus thatincludes a program memory that holds instructions of a program fetchedand executed by the apparatus and computer program product encoded in atleast one non-transitory computer usable medium for use with a computingdevice.

Description of the Related Art

Recently, there has been a resurgence of interest in artificial neuralnetworks (ANN), and such research has commonly been termed deeplearning, computer learning and similar terms. The increase ingeneral-purpose processor computation power has given rise to therenewed interest that waned a couple of decades ago. Recent applicationsof ANNs have included speech and image recognition, along with others.There appears to be an increasing demand for improved performance andefficiency of computations associated with ANNs.

SUMMARY

The following summary is illustrative only and is not intended to belimiting in any way. That is, the following summary is provided tointroduce concepts, highlights, benefits and advantages of the novel andnon-obvious techniques described herein. Select, not all,implementations are described further in the detailed description below.Thus, the following summary is not intended to identify essentialfeatures of the claimed subject matter, nor is it intended for use indetermining the scope of the claimed subject matter.

A method for operating an apparatus that includes a program memory thatholds instructions of a program fetched and executed by the apparatusand computer program product encoded in at least one non-transitorycomputer usable medium for use with a computing device are provided inthe disclosure.

In one exemplary embodiment, a method for operating an apparatus thatincludes a program memory that holds instructions of a program fetchedand executed by the apparatus, a data memory that holds data processedby the instructions, a status register that holds a status that theapparatus updates during its operation, wherein the status has fieldscomprising: a program memory address at which a most recent instructionis fetched from the program memory, a data memory access address atwhich data has most recently been accessed in the data memory by theapparatus and a repeat count that indicates a number of times anoperation specified in a current program instruction remains to beperformed, the apparatus further including a condition register havingcondition fields corresponding to the status fields held in the statusregister, the method comprising: writing, by an instruction of theprogram, the condition register with a condition comprising one or moreof the condition fields; and generating an interrupt request to aprocessing core in response to detecting that the status held in thestatus register satisfies the condition specified in the conditionregister.

In one exemplary embodiment, a computer program product encoded in atleast one non-transitory computer usable medium for use with a computingdevice, the computer program product comprising: computer usable programcode embodied in said medium, for specifying an apparatus, the computerusable program code comprising: first program code for specifying anoutput for generating an interrupt request to a processing core coupledto the apparatus; second program code for specifying a program memorythat holds instructions of a program fetched and executed by theapparatus; third program code for specifying a data memory that holdsdata processed by the instructions; fourth program code for specifying astatus register that holds a status that the apparatus updates duringits operation, the status having fields comprising: a program memoryaddress at which a most recent instruction is fetched from the programmemory; a data memory access address at which data has most recentlybeen accessed in the data memory by the apparatus; and a repeat countthat indicates a number of times an operation specified in a currentprogram instruction remains to be performed; fifth program code forspecifying a condition register having condition fields corresponding tothe status fields held in the status register; wherein the conditionregister is writeable, by an instruction of the program, with acondition comprising one or more of the condition fields; and sixthprogram code for specifying control logic that generates on the outputan interrupt request to the processing core in response to detectingthat the status held in the status register satisfies the conditionspecified in the condition register.

BRIEF DESCRIPTION OF THE DRAWINGS

The present disclosure can be more fully understood by reading thesubsequent detailed description and examples with references made to theaccompanying drawings, wherein:

FIG. 1 is a block diagram illustrating a processor that includes aneural network unit (NNU).

FIG. 2 is a block diagram illustrating a NPU of FIG. 1.

FIG. 3 is a block diagram illustrating an embodiment of the arrangementof the N mux-regs of the N NPUs of the NNU of FIG. 1 to illustrate theiroperation as an N-word rotater, or circular shifter, for a row of datawords received from the data RAM of FIG. 1.

FIG. 4 is a table illustrating a program for storage in the programmemory of and execution by the NNU of FIG. 1.

FIG. 5 is a timing diagram illustrating the execution of the program ofFIG. 4 by the NNU.

FIG. 6A is a block diagram illustrating the NNU of FIG. 1 to execute theprogram of FIG. 4.

FIG. 6B is a flowchart illustrating operation of the processor of FIG. 1to perform an architectural program that uses the NNU to performmultiply-accumulate-activation function computations classicallyassociated with neurons of hidden layers of an artificial neural networksuch as performed by the program of FIG. 4.

FIG. 7 is a block diagram illustrating a NPU of FIG. 1 according to analternate embodiment.

FIG. 8 is a block diagram illustrating a NPU of FIG. 1 according to analternate embodiment.

FIG. 9 is a table illustrating a program for storage in the programmemory of and execution by the NNU of FIG. 1.

FIG. 10 is a timing diagram illustrating the execution of the program ofFIG. 9 by the NNU.

FIG. 11 is a block diagram illustrating an embodiment of the NNU of FIG.1 is shown. In the embodiment of FIG. 11, a neuron is split into twoportions, the activation function unit portion and the ALU portion(which also includes the shift register portion), and each activationfunction unit portion is shared by multiple ALU portions.

FIG. 12 is a timing diagram illustrating the execution of the program ofFIG. 4 by the NNU of FIG. 11.

FIG. 13 is a timing diagram illustrating the execution of the program ofFIG. 4 by the NNU of FIG. 11.

FIG. 14 is a block diagram illustrating a move to neural network (MTNN)architectural instruction and its operation with respect to portions ofthe NNU of FIG. 1.

FIG. 15 is a block diagram illustrating a move from neural network(MFNN) architectural instruction and its operation with respect toportions of the NNU of FIG. 1.

FIG. 16 is a block diagram illustrating an embodiment of the data RAM ofFIG. 1.

FIG. 17 is a block diagram illustrating an embodiment of the weight RAMof FIG. 1 and a buffer.

FIG. 18 is a block diagram illustrating a dynamically configurable NPUof FIG. 1.

FIG. 19 is a block diagram illustrating an embodiment of the arrangementof the 2N mux-regs of the N NPUs of the NNU of FIG. 1 according to theembodiment of FIG. 18 to illustrate their operation as a rotater for arow of data words received from the data RAM of FIG. 1.

FIG. 20 is a table illustrating a program for storage in the programmemory of and execution by the NNU of FIG. 1 having NPUs according tothe embodiment of FIG. 18.

FIG. 21 is a timing diagram illustrating the execution of the program ofFIG. 20 by the NNU that includes NPUs of FIG. 18 operating in a narrowconfiguration.

FIG. 22 is a block diagram illustrating the NNU of FIG. 1 including theNPUs of FIG. 18 to execute the program of FIG. 20.

FIG. 23 is a block diagram illustrating a dynamically configurable NPUof FIG. 1 according to an alternate embodiment.

FIG. 24 is a block diagram illustrating an example of data structuresused by the NNU of FIG. 1 to perform a convolution operation.

FIG. 25 is a flowchart illustrating operation of the processor of FIG. 1to perform an architectural program that uses the NNU to perform aconvolution of the convolution kernel with the data array of FIG. 24.

FIG. 26A is a program listing of an NNU program that performs aconvolution of a data matrix with the convolution kernel of FIG. 24 andwrites it back to the weight RAM.

FIG. 26B is a block diagram illustrating certain fields of the controlregister of the NNU of FIG. 1 according to one embodiment.

FIG. 27 is a block diagram illustrating an example of the weight RAM ofFIG. 1 populated with input data upon which a pooling operation isperformed by the NNU of FIG. 1.

FIG. 28 is a program listing of an NNU program that performs a poolingoperation of the input data matrix of FIG. 27 and writes it back to theweight RAM.

FIG. 29A is a block diagram illustrating an embodiment of the controlregister of FIG. 1.

FIG. 29B is a block diagram illustrating an embodiment of the controlregister of FIG. 1 according to an alternate embodiment.

FIG. 29C is a block diagram illustrating an embodiment of the reciprocalof FIG. 29A stored as two parts according to one embodiment.

FIG. 30 is a block diagram illustrating in more detail an embodiment ofan AFU of FIG. 2.

FIG. 31 is an example of operation of the AFU of FIG. 30.

FIG. 32 is a second example of operation of the AFU of FIG. 30.

FIG. 33 is a third example of operation of the AFU of FIG. 30.

FIG. 34 is a block diagram illustrating the processor of FIG. 1 and inmore detail portions of the NNU of FIG. 1.

FIG. 35 is a block diagram illustrating a processor that includes avariable rate NNU.

FIG. 36A is a timing diagram illustrating an example of operation of theprocessor with the NNU operating in normal mode, i.e., at the primaryclock rate.

FIG. 36B is a timing diagram illustrating an example of operation of theprocessor with the NNU operating in relaxed mode, i.e., at a rate thatis less than the primary clock rate.

FIG. 37 is a flowchart illustrating operation of the processor of FIG.35.

FIG. 38 is a block diagram illustrating the sequence of the NNU in moredetail.

FIG. 39 is a block diagram illustrating certain fields of the controland status register of the NNU.

FIG. 40 is a block diagram illustrating an embodiment of portions of theNNU.

FIG. 41 is a block diagram illustrating a processor is shown.

FIG. 42 is a block diagram illustrating the ring stop of FIG. 41 in moredetail.

FIG. 43 is a block diagram illustrating in more detail the slaveinterface of FIG. 42.

FIG. 44 is a block diagram illustrating in more detail the masterinterface 0 of FIG. 42.

FIG. 45 is a block diagram illustrating the ring stop of FIG. 42 andportions of a ring bus-coupled embodiment of the NNU.

FIG. 46 is a block diagram illustrating a ring bus-coupled embodiment ofthe NNU.

FIG. 47 is a block diagram illustrating an embodiment of a NNU.

FIG. 48 is a block diagram illustrating in more detail the interruptcondition register of FIG. 47.

FIG. 49 is a block diagram illustrating in more detail the statusregister of FIG. 47.

FIG. 50 is a flowchart illustrating operation of the NNU of FIG. 47 togenerate an interrupt request to a core based upon conditions.

FIG. 51 is a table illustrating a program for storage in the programmemory of and execution by the NNU of FIG. 47.

FIG. 52 is a set interrupt condition instruction according to analternate embodiment for storage in the program memory of and executionby the NNU of FIG. 47.

FIG. 53 is a table illustrating a program for storage in the programmemory of and execution by the NNU of FIG. 47.

DETAILED DESCRIPTION OF THE EMBODIMENTS

Processor with Architectural Neural Network Unit

Referring now to FIG. 1, a block diagram illustrating a processor 100that includes a neural network unit (NNU) 121 is shown. The processor100 includes an instruction fetch unit 101, an instruction cache 102,and instruction translator 104, a rename unit 106, reservation stations108, media registers 118, general purpose registers (GPR) 116, executionunits 112 other than the NNU 121, and a memory subsystem 114.

The processor 100 is an electronic device that functions as a centralprocessing unit (CPU) on an integrated circuit. The processor 100receives digital data as input, processes the data according toinstructions fetched from a memory, and generates results of operationsprescribed by the instructions as output. The processor 100 may beemployed in a desktop, mobile, or tablet computer, and is employed foruses such as computation, text editing, multimedia display, and Internetbrowsing. The processor 100 may also be disposed in an embedded systemto control a wide variety of devices including appliances, mobiletelephones, smart phones, automobiles and industrial control devices. ACPU is the electronic circuits (i.e., “hardware”) that execute theinstructions of a computer program (also known as a “computerapplication” or “application”) by performing operations on data thatinclude arithmetic operations, logical operations, and input/outputoperations. An integrated circuit (IC) is a set of electronic circuitsfabricated on a small piece of semiconductor material, typicallysilicon. An IC is also referred to as a chip, a microchip, or a die.

The instruction fetch unit 101 controls the fetching of architecturalinstructions 103 from system memory (not shown) into the instructioncache 102. The instruction fetch unit 101 provides a fetch address tothe instruction cache 102 that specifies a memory address at which theprocessor 100 fetches a cache line of architectural instruction bytesinto the instruction cache 102. The fetch address is based on thecurrent value of the instruction pointer (not shown), or programcounter, of the processor 100. Normally, the program counter isincremented sequentially by the size of an instruction unless a controlinstruction is encountered in the instruction stream, such as a branch,call or return instruction, or an exception condition occurs, such as aninterrupt, trap, exception or fault, in which case the program counteris updated with a non-sequential address, such as a branch targetaddress, return address or exception vector. Generally speaking, theprogram counter is updated in response to the execution of instructionsby the execution units 112/121. The program counter may also be updatedin response to detection of an exception condition such as theinstruction translator 104 encountering an instruction 103 that is notdefined by the instruction set architecture of the processor 100.

The instruction cache 102 caches the architectural instructions 103fetched from a system memory that is coupled to the processor 100. Thearchitectural instructions 103 include a move to neural network (MTNN)instruction and a move from neural network (MFNN) instruction, which aredescribed in more detail below. In one embodiment, the architecturalinstructions 103 are instructions of the x86 instruction setarchitecture (ISA), with the addition of the MTNN and MFNN instructions.In the context of the present disclosure, an x86 ISA processor as aprocessor that generates the same results at the instruction setarchitecture level that an Intel® 80386® processor generates when itexecutes the same machine language instructions. However, otherembodiments contemplate other instruction set architectures, such asAdvanced RISC Machines (ARM)®, Sun SPARC®, or PowerPC®. The instructioncache 102 provides the architectural instructions 103 to the instructiontranslator 104, which translates the architectural instructions 103 intomicroinstructions 105.

The microinstructions 105 are provided to the rename unit 106 andeventually executed by the execution units 112/121. Themicroinstructions 105 implement the architectural instructions.Preferably, the instruction translator 104 includes a first portion thattranslates frequently executed and/or relatively less complexarchitectural instructions 103 into microinstructions 105. Theinstruction translator 104 also includes a second portion that includesa microcode unit (not shown). The microcode unit includes a microcodememory that holds microcode instructions that implement complex and/orinfrequently used instructions of the architectural instruction set. Themicrocode unit also includes a microsequencer that provides anon-architectural micro-program counter (micro-PC) to the microcodememory. Preferably, the microcode instructions are translated by amicrotranslator (not shown) into the microinstructions 105. A selectorselects the microinstructions 105 from either the first portion or thesecond portion for provision to the rename unit 106, depending uponwhether or not the microcode unit currently has control.

The rename unit 106 renames architectural registers specified in thearchitectural instructions 103 to physical registers of the processor100. Preferably, the processor 100 includes a reorder buffer (notshown). The rename unit 106 allocates, in program order, an entry in thereorder buffer for each microinstruction 105. This enables the processor100 to retire the microinstructions 105, and their correspondingarchitectural instructions 103, in program order. In one embodiment, themedia registers 118 are 256 bits wide and the GPR 116 are 64 bits wide.In one embodiment, the media registers 118 are x86 media registers, suchas Advanced Vector Extensions (AVX) registers.

In one embodiment, each entry in the reorder buffer includes storage forthe result of the microinstruction 105; additionally, the processor 100includes an architectural register file that includes a physicalregister for each of the architectural registers, e.g., the mediaregisters 118 and the GPR 116 and other architectural registers.(Preferably, there are separate register files for the media registers118 and GPR 116, for example, since they are different sizes.) For eachsource operand of a microinstruction 105 that specifies an architecturalregister, the rename unit populates the source operand field in themicroinstruction 105 with the reorder buffer index of the newest oldermicroinstruction 105 that writes to the architectural register. When theexecution unit 112/121 completes execution of the microinstruction 105,it writes the result to the microinstruction's 105 reorder buffer entry.When the microinstruction 105 retires, a retire unit (not shown) writesthe result from the microinstruction's reorder buffer entry to theregister of the physical register file associated with the architecturaldestination register specified by the retiring microinstruction 105.

In another embodiment, the processor 100 includes a physical registerfile that includes more physical registers than the number ofarchitectural registers, but does not include an architectural registerfile, and the reorder buffer entries do not include result storage.(Preferably, there are separate physical register files for the mediaregisters 118 and GPR 116, for example, since they are different sizes.)The processor 100 also includes a pointer table with an associatedpointer for each architectural register. For the operand of amicroinstruction 105 that specifies an architectural register, therename unit populates the destination operand field in themicroinstruction 105 with a pointer to a free register in the physicalregister file. If no registers are free in the physical register file,the rename unit 106 stalls the pipeline. For each source operand of amicroinstruction 105 that specifies an architectural register, therename unit populates the source operand field in the microinstruction105 with a pointer to the register in the physical register fileassigned to the newest older microinstruction 105 that writes to thearchitectural register. When the execution unit 112/121 completesexecution of the microinstruction 105, it writes the result to aregister of the physical register file pointed to by themicroinstruction's 105 destination operand field. When themicroinstruction 105 retires, the retire unit copies themicroinstruction's 105 destination operand field value to the pointer inthe pointer table associated with the architectural destination registerspecified by the retiring microinstruction 105.

The reservation stations 108 hold microinstructions 105 until they areready to be issued to an execution unit 112/121 for execution. Amicroinstruction 105 is ready to be issued when all of its sourceoperands are available and an execution unit 112/121 is available toexecute it. The execution units 112/121 receive register source operandsfrom the reorder buffer or the architectural register file in the firstembodiment or from the physical register file in the second embodimentdescribed above. Additionally, the execution units 112/121 may receiveregister source operands directly from the execution units 112/121 viaresult forwarding buses (not shown). Additionally, the execution units112/121 may receive from the reservation stations 108 immediate operandsspecified by the microinstructions 105. As discussed in more detailbelow, the MTNN and MFNN architectural instructions 103 include animmediate operand that specifies a function to be performed by the NNU121 that is provided in one of the one or more microinstructions 105into which the MTNN and MFNN architectural instructions 103 aretranslated.

The execution units 112 include one or more load/store units (not shown)that load data from the memory subsystem 114 and store data to thememory subsystem 114. Preferably, the memory subsystem 114 includes amemory management unit (not shown), which may include, e.g., translationlookaside buffers and a tablewalk unit, a level-1 data cache (and theinstruction cache 102), a level-2 unified cache, and a bus interfaceunit that interfaces the processor 100 to system memory. In oneembodiment, the processor 100 of FIG. 1 is representative of aprocessing core that is one of multiple processing cores in a multi-coreprocessor that share a last-level cache memory. The execution units 112may also include integer units, media units, floating-point units and abranch unit.

The NNU 121 includes a weight random access memory (RAM) 124, a data RAM122, N neural processing units (NPUs) 126, a program memory 129, asequencer 128 and control and status registers 127. The NPUs 126function conceptually as neurons in a neural network. The weight RAM124, data RAM 122 and program memory 129 are all writable and readablevia the MTNN and MFNN architectural instructions 103, respectively. Theweight RAM 124 is arranged as W rows of N weight words, and the data RAM122 is arranged as D rows of N data words. Each data word and eachweight word is a plurality of bits, preferably 8 bits, 9 bits, 12 bitsor 16 bits. Each data word functions as the output value (also sometimesreferred to as an activation) of a neuron of the previous layer in thenetwork, and each weight word functions as a weight associated with aconnection coming into a neuron of the instant layer of the network.Although in many uses of the NNU 121 the words, or operands, held in theweight RAM 124 are in fact weights associated with a connection cominginto a neuron, it should be understood that in other uses of the NNU 121the words held in the weight RAM 124 are not weights, but arenevertheless referred to as “weight words” because they are stored inthe weight RAM 124. For example, in some uses of the NNU 121, e.g., theconvolution example of FIGS. 24 through 26A or the pooling example ofFIGS. 27 through 28, the weight RAM 124 may hold non-weights, such aselements of a data matrix, e.g., image pixel data. Similarly, althoughin many uses of the NNU 121 the words, or operands, held in the data RAM122 are in fact the output value, or activation, of a neuron, it shouldbe understood that in other uses of the NNU 121 the words held in thedata RAM 122 are not such, but are nevertheless referred to as “datawords” because they are stored in the data RAM 122. For example, in someuses of the NNU 121, e.g., the convolution example of FIGS. 24 through26A, the data RAM 122 may hold non-neuron outputs, such as elements of aconvolution kernel.

In one embodiment, the NPUs 126 and sequencer 128 comprise combinatoriallogic, sequential logic, state machines, or a combination thereof. Anarchitectural instruction (e.g., MFNN instruction 1500) loads thecontents of the status register 127 into one of the GPR 116 to determinethe status of the NNU 121, e.g., that the NNU 121 has completed acommand or completed a program the NNU 121 was running from the programmemory 129, or that the NNU 121 is free to receive a new command orstart a new NNU program.

Advantageously, the number of NPUs 126 may be increased as needed, andthe size of the weight RAM 124 and data RAM 122 may be extended in bothwidth and depth accordingly. Preferably, the weight RAM 124 is largersince in a classic neural network layer there are many connections, andtherefore weights, associated with each neuron. Various embodiments aredescribed herein regarding the size of the data and weight words and thesizes of the weight RAM 124 and data RAM 122 and the number of NPUs 126.In one embodiment, a NNU 121 with a 64 KB (8192 bits×64 rows) data RAM122, a 2 MB (8192 bits×2048 rows) weight RAM 124, and 512 NPUs 126 isimplemented in a Taiwan Semiconductor Manufacturing Company, Limited(TSMC) 16 nm process and occupies approximately a 3.3 mm² area.

The sequencer 128 fetches instructions from the program memory 129 andexecutes them, which includes, among other things, generating addressand control signals for provision to the data RAM 122, weight RAM 124and NPUs 126. The sequencer 128 generates a memory address 123 and aread command for provision to the data RAM 122 to select one of the Drows of N data words for provision to the N NPUs 126. The sequencer 128also generates a memory address 125 and a read command for provision tothe weight RAM 124 to select one of the W rows of N weight words forprovision to the N NPUs 126. The sequence of the addresses 123 and 125generated by the sequencer 128 for provision to the NPUs 126 determinesthe “connections” between neurons. The sequencer 128 also generates amemory address 123 and a write command for provision to the data RAM 122to select one of the D rows of N data words for writing from the N NPUs126. The sequencer 128 also generates a memory address 125 and a writecommand for provision to the weight RAM 124 to select one of the W rowsof N weight words for writing from the N NPUs 126. The sequencer 128also generates a memory address 131 to the program memory 129 to selecta NNU instruction that is provided to the sequencer 128, such asdescribed below. The memory address 131 corresponds to a program counter(not shown) that the sequencer 128 generally increments throughsequential locations of the program memory 129 unless the sequencer 128encounters a control instruction, such as a loop instruction (see, forexample, FIG. 26A), in which case the sequencer 128 updates the programcounter to the target address of the control instruction. The sequencer128 also generates control signals to the NPUs 126 to instruct them toperform various operations or functions, such as initialization,arithmetic/logical operations, rotate and shift operations, activationfunctions and write back operations, examples of which are described inmore detail below (see, for example, micro-operations 3418 of FIG. 34).

The N NPUs 126 generate N result words 133 that may be written back to arow of the weight RAM 124 or to the data RAM 122. Preferably, the weightRAM 124 and the data RAM 122 are directly coupled to the N NPUs 126.More specifically, the weight RAM 124 and data RAM 122 are dedicated tothe NPUs 126 and are not shared by the other execution units 112 of theprocessor 100, and the NPUs 126 are capable of consuming a row from oneor both of the weight RAM 124 and data RAM 122 each clock cycle in asustained manner, preferably in a pipelined fashion. In one embodiment,each of the data RAM 122 and the weight RAM 124 is capable of providing8192 bits to the NPUs 126 each clock cycle. The 8192 bits may beconsumed as 512 16-bit words or as 1024 8-bit words, as described inmore detail below.

Advantageously, the size of the data set that may be processed by theNNU 121 is not limited to the size of the weight RAM 124 and data RAM122, but is rather only limited by the size of system memory since dataand weights may be moved between system memory and the weight RAM 124and data RAM 122 using the MTNN and MFNN instructions (e.g., through themedia registers 118). In one embodiment, the data RAM 122 is dual-portedto enable data words to be written to the data RAM 122 while data wordsare concurrently read from or written to the data RAM 122. Furthermore,the large memory hierarchy of the memory subsystem 114, including thecache memories, provides very high data bandwidth for the transfersbetween the system memory and the NNU 121. Still further, preferably,the memory subsystem 114 includes hardware data prefetchers that trackmemory access patterns, such as loads of neural data and weights fromsystem memory, and perform data prefetches into the cache hierarchy tofacilitate high bandwidth and low latency transfers to the weight RAM124 and data RAM 122.

Although embodiments are described in which one of the operands providedto each NPU 126 is provided from a weight memory and is denoted aweight, which are commonly used in neural networks, it should beunderstood that the operands may be other types of data associated withcalculations whose speed may be improved by the apparatuses described.

Referring now to FIG. 2, a block diagram illustrating a NPU 126 of FIG.1 is shown. The NPU 126 operates to perform many functions, oroperations. In particular, advantageously the NPU 126 is configured tooperate as a neuron, or node, in an artificial neural network to performa classic multiply-accumulate function, or operation. That is, generallyspeaking, the NPU 126 (neuron) is configured to: (1) receive an inputvalue from each neuron having a connection to it, typically but notnecessarily from the immediately previous layer of the artificial neuralnetwork; (2) multiply each input value by a corresponding weight valueassociated with the connection to generate a product; (3) add all theproducts to generate a sum; and (4) perform an activation function onthe sum to generate the output of the neuron. However, rather thanperforming all the multiplies associated with all the connection inputsand then adding all the products together as in a conventional manner,advantageously each neuron is configured to perform, in a given clockcycle, the weight multiply operation associated with one of theconnection inputs and then add (accumulate) the product with theaccumulated value of the products associated with connection inputsprocessed in previous clock cycles up to that point. Assuming there areM connections to the neuron, after all M products have been accumulated(which takes approximately M clock cycles), the neuron performs theactivation function on the accumulated value to generate the output, orresult. This has the advantage of requiring fewer multipliers and asmaller, simpler and faster adder circuit (e.g., a 2-input adder) in theneuron than an adder that would be required to add all, or even a subsetof, the products associated with all the connection inputs. This, inturn, has the advantage of facilitating a very large number (N) ofneurons (NPUs 126) in the NNU 121 so that after approximately M clockcycles, the NNU 121 has generated the output for all of the large number(N) of neurons. Finally, the NNU 121 constructed of such neurons has theadvantage of efficiently performing as an artificial neural networklayer for a large number of different connection inputs. That is, as Mincreases or decreases for different layers, the number of clock cyclesrequired to generate the neuron outputs correspondingly increases ordecreases, and the resources (e.g., multipliers and accumulators) arefully utilized; whereas, in a more conventional design, some of themultipliers and a portion of the adder may not be utilized for smallervalues of M. Thus, the embodiments described herein have the benefit offlexibility and efficiency with respect to the number of connectioninputs to the neurons of the NNU 121, and provide extremely highperformance.

The NPU 126 includes a register 205, a 2-input multiplexed register(mux-reg) 208, an arithmetic logic unit (ALU) 204, an accumulator 202,and an activation function unit (AFU) 212. The register 205 receives aweight word 206 from the weight RAM 124 and provides its output 203 on asubsequent clock cycle. The mux-reg 208 selects one of its inputs 207 or211 to store in its register and then to provide on its output 209 on asubsequent clock cycle. One input 207 receives a data word from the dataRAM 122. The other input 211 receives the output 209 of the adjacent NPU126. The NPU 126 shown in FIG. 2 is denoted NPU J from among the N NPUs126 of FIG. 1. That is, NPU J is a representative instance of the N NPUs126. Preferably, the mux-reg 208 input 211 of NPU J receives the mux-reg208 output 209 of NPU 126 instance J−1, and the mux-reg 208 output 209of NPU J is provided to the mux-reg 208 input 211 of NPU 126 instanceJ+1. In this manner, the mux-regs 208 of the N NPUs 126 collectivelyoperate as an N-word rotater, or circular shifter, as described in moredetail below with respect to FIG. 3. A control input 213 controls whichof the two inputs the mux-reg 208 selects to store in its register andthat is subsequently provided on the output 209.

The ALU 204 has three inputs. One input receives the weight word 203from the register 205. Another input receives the output 209 of themux-reg 208. The other input receives the output 217 of the accumulator202. The ALU 204 performs arithmetic and/or logical operations on itsinputs to generate a result provided on its output. Preferably, thearithmetic and/or logical operations to be performed by the ALU 204 arespecified by instructions stored in the program memory 129. For example,the multiply-accumulate instruction of FIG. 4 specifies amultiply-accumulate operation, i.e., the result 215 is the sum of theaccumulator 202 value 217 and the product of the weight word 203 and thedata word of the mux-reg 208 output 209. Other operations that may bespecified include, but are not limited to: the result 215 is thepassed-through value of the mux-reg output 209; the result 215 is thepassed-through value of the weight word 203; the result 215 is zero; theresult 215 is the passed-through value of the weight word 203; theresult 215 is the sum of the accumulator 202 value 217 and the weightword 203; the result 215 is the sum of the accumulator 202 value 217 andthe mux-reg output 209; the result 215 is the maximum of the accumulator202 value 217 and the weight word 203; the result 215 is the maximum ofthe accumulator 202 value 217 and the mux-reg output 209.

The ALU 204 provides its output 215 to the accumulator 202 for storagetherein. The ALU 204 includes a multiplier 242 that multiplies theweight word 203 and the data word of the mux-reg 208 output 209 togenerate a product 246. In one embodiment, the multiplier 242 multipliestwo 16-bit operands to generate a 32-bit result. The ALU 204 alsoincludes an adder 244 that adds the product 246 to the accumulator 202output 217 to generate a sum, which is the result 215 accumulated in theaccumulator 202 for storage in the accumulator 202. In one embodiment,the adder 244 adds the 32-bit result of the multiplier 242 to a 41-bitvalue 217 of the accumulator 202 to generate a 41-bit result. In thismanner, using the rotater aspect of the mux-reg 208 over the course ofmultiple clock cycles, the NPU 126 accomplishes a sum of products for aneuron as required by neural networks. The ALU 204 may also includeother circuit elements to perform other arithmetic/logical operationssuch as those above. In one embodiment, a second adder subtracts theweight word 203 from the data word of the mux-reg 208 output 209 togenerate a difference, which the adder 244 then adds to the accumulator202 output 217 to generate a sum 215, which is the result accumulated inthe accumulator 202. In this manner, over the course of multiple clockcycles, the NPU 126 may accomplish a sum of differences. Preferably,although the weight word 203 and the data word 209 are the same size (inbits), they may have different binary point locations, as described inmore detail below. Preferably, the multiplier 242 and adder 244 areinteger multipliers and adders, as described in more detail below, toadvantageously accomplish less complex, smaller, faster and lower powerconsuming ALUs 204 than floating-point counterparts. However, it shouldbe understood that in other embodiments the ALU 204 performsfloating-point operations.

Although FIG. 2 shows only a multiplier 242 and adder 244 in the ALU204, preferably the ALU 204 includes other elements to perform the otheroperations described above. For example, preferably the ALU 204 includesa comparator (not shown) for comparing the accumulator 202 with adata/weight word and a mux (not shown) that selects the larger (maximum)of the two values indicated by the comparator for storage in theaccumulator 202. For another example, preferably the ALU 204 includesselection logic (not shown) that bypasses the multiplier 242 with adata/weight word to enable the adder 244 to add the data/weight word tothe accumulator 202 value 217 to generate a sum for storage in theaccumulator 202. These additional operations are described in moredetail below, for example, with respect to FIGS. 18 through 29A, and maybe useful for performing convolution and pooling operations, forexample.

The AFU 212 receives the output 217 of the accumulator 202. The AFU 212performs an activation function on the accumulator 202 output 217 togenerate a result 133 of FIG. 1. Generally speaking, the activationfunction in a neuron of an intermediate layer of an artificial neuralnetwork may serve to normalize the accumulated sum of products,preferably in a non-linear fashion. To “normalize” the accumulated sum,the activation function of an instant neuron produces a resulting valuewithin a range of values that neurons connected to the instant neuronexpect to receive as input. (The normalized result is sometimes referredto as an “activation” that, as described herein, is the output of aninstant node that a receiving node multiplies by a weight associatedwith the connection between the outputting node and the receiving nodeto generate a product that is accumulated with other products associatedwith the other input connections to the receiving node.) For example,the receiving/connected neurons may expect to receive as input a valuebetween 0 and 1, in which case the outputting neuron may need tonon-linearly squash and/or adjust (e.g., upward shift to transformnegative to positive values) the accumulated sum that is outside the 0to 1 range to a value within the expected range. Thus, the AFU 212performs an operation on the accumulator 202 value 217 to bring theresult 133 within a known range. The results 133 of all of the N NPUs126 may be written back concurrently to either the data RAM 122 or tothe weight RAM 124. Preferably, the AFU 212 is configured to performmultiple activation functions, and an input, e.g., from the controlregister 127, selects one of the activation functions to perform on theaccumulator 202 output 217. The activation functions may include, butare not limited to, a step function, a rectify function, a sigmoidfunction, a hyperbolic tangent (tanh) function and a softplus function(also referred to as smooth rectify). The softplus function is theanalytic function f(x)=ln(1+e^(x)), that is, the natural logarithm ofthe sum of one and e^(x), where “e^(x)” is Euler's number and x is theinput 217 to the function. Preferably, the activation functions may alsoinclude a pass-through function that passes through the accumulator 202value 217, or a portion thereof, as described in more detail below. Inone embodiment, circuitry of the AFU 212 performs the activationfunction in a single clock cycle. In one embodiment, the AFU 212comprises tables that receive the accumulated value and output a valuethat closely approximates the value that the true activation functionwould provide for some of the activation functions, e.g., sigmoid,hyperbolic tangent, softplus.

Preferably, the width (in bits) of the accumulator 202 is greater thanthe width of the AFU 212 output 133. For example, in one embodiment, theaccumulator is 41 bits wide, to avoid loss of precision in theaccumulation of up to 512 32-bit products (as described in more detailbelow, e.g., with respect to FIG. 30), and the result 133 is 16 bitswide. In one embodiment, an example of which is described in more detailbelow with respect to FIG. 8, during successive clock cycles differentportions of the “raw” accumulator 202 output 217 value are passedthrough the AFU 212 and written back to the data RAM 122 or weight RAM124. This enables the raw accumulator 202 values to be loaded back tothe media registers 118 via the MFNN instruction so that instructionsexecuting on other execution units 112 of the processor 100 may performcomplex activation functions that the AFU 212 is not capable ofperforming, such as the well-known softmax activation function, alsoreferred to as the normalized exponential function. In one embodiment,the processor 100 instruction set architecture includes an instructionthat performs the exponential function, commonly referred to as e^(x) orexp(x), which may be used to speed up the performance of the softmaxactivation function by the other execution units 112 of the processor100.

In one embodiment, the NPU 126 is pipelined. For example, the NPU 126may include registers of the ALU 204, such as a register between themultiplier and the adder and/or other circuits of the ALU 204, and aregister that holds the output of the AFU 212. Other embodiments of theNPU 126 are described below.

Referring now to FIG. 3, a block diagram illustrating an embodiment ofthe arrangement of the N mux-regs 208 of the N NPUs 126 of the NNU 121of FIG. 1 to illustrate their operation as an N-word rotater, orcircular shifter, for a row of data words 207 received from the data RAM122 of FIG. 1 is shown. In the embodiment of FIG. 3, N is 512 such thatthe NNU 121 has 512 mux-regs 208, denoted 0 through 511, correspondingto 512 NPUs 126, as shown. Each mux-reg 208 receives its correspondingdata word 207 of one row of the D rows of the data RAM 122. That is,mux-reg 0 receives data word 0 of the data RAM 122 row, mux-reg 1receives data word 1 of the data RAM 122 row, mux-reg 2 receives dataword 2 of the data RAM 122 row, and so forth to mux-reg 511 receivesdata word 511 of the data RAM 122 row. Additionally, mux-reg 1 receiveson its other input 211 the output 209 of mux-reg 0, mux-reg 2 receiveson its other input 211 the output 209 of mux-reg 1, mux-reg 3 receiveson its other input 211 the output 209 of mux-reg 2, and so forth tomux-reg 511 that receives on its other input 211 the output 209 ofmux-reg 510, and mux-reg 0 receives on its other input 211 the output209 of mux-reg 511. Each of the mux-regs 208 receives the control input213 that controls whether to select the data word 207 or the rotatedinput 211. As described in more detail below, in one mode of operation,on a first clock cycle, the control input 213 controls each of themux-regs 208 to select the data word 207 for storage in the register andfor subsequent provision to the ALU 204; and during subsequent clockcycles (e.g., M-1 clock cycles as described above), the control input213 controls each of the mux-regs 208 to select the rotated input 211for storage in the register and for subsequent provision to the ALU 204.

Although FIG. 3 (and FIGS. 7 and 19 below) describe an embodiment inwhich the NPUs 126 are configured to rotate the values of the mux-regs208/705 to the right, i.e., from NPU J to NPU J+1, embodiments arecontemplated (such as with respect to the embodiment of FIGS. 24 through26) in which the NPUs 126 are configured to rotate the values of themux-regs 208/705 to the left, i.e., from NPU J to NPU J−1. Furthermore,embodiments are contemplated in which the NPUs 126 are configured torotate the values of the mux-regs 208/705 selectively to the left or tothe right, e.g., as specified by the NNU instructions.

Referring now to FIG. 4, a table illustrating a program for storage inthe program memory 129 of and execution by the NNU 121 of FIG. 1 isshown. The example program performs the calculations associated with alayer of an artificial neural network as described above. In the tableof FIG. 4, four rows and three columns are shown. Each row correspondsto an address of the program memory 129 denoted in the first column. Thesecond column specifies the instruction, and the third column indicatesthe number of clock cycles associated with the instruction. Preferably,the number of clock cycles indicates the effective number of clocks in aclocks-per-instruction type value in a pipelined embodiment, rather thanthe latency of the instruction. As shown, each of the instructions hasan associated one clock cycle due to the pipelined nature of the NNU121, with the exception of the instruction at address 2 which requires511 clocks because it effectively repeats itself 511 times, as describedin more detail below.

For each instruction of the program, all of the NPUs 126 perform theinstruction in parallel. That is, all N NPUs 126 performs theinstruction in the first row in the same clock cycle(s), all N NPUs 126performs the instruction in the second row in the same clock cycle(s),and so forth. However, other embodiments are described below in whichsome of the instructions are performed in a partially parallel andpartially sequential fashion, e.g., the activation function and outputinstructions at addresses 3 and 4 in an embodiment in which NPUs 126share an activation function unit, e.g., with respect to the embodimentof FIG. 11. The example of FIG. 4 assumes 512 neurons (NPUs 126) of alayer, each having 512 connection inputs from a previous layer of 512neurons, for a total of 256K connections. Each neuron receives a 16-bitdata value from each connection input and multiplies the 16-bit datavalue by an appropriate 16-bit weight value.

The first row, at address 0 (although other addresses may be specified),specifies an initialize NPU instruction. The initialize instructionclears the accumulator 202 value to zero. In one embodiment, theinitialize instruction can also specify to load the accumulator 202 withthe corresponding word of a row of the data RAM 122 or weight RAM 124whose address is specified by the instruction. The initializeinstruction also loads configuration values into the control register127, as described in more detail below with respect to FIGS. 29A and29B. For example, the width of the data word 207 and weight word 209 maybe loaded, which may be used by the ALU 204 to determine the sizes ofthe operations performed by the circuits and may affect the result 215stored in the accumulator 202. In one embodiment, the NPU 126 includes acircuit that saturates the ALU 204 output 215 before being stored in theaccumulator 202, and the initialize instruction loads a configurationvalue into the circuit to affect the saturation. In one embodiment, theaccumulator 202 may also be cleared to a zero value by so specifying inan ALU function instruction (e.g., multiply-accumulate instruction ataddress 1) or an output instruction, such as the write AFU outputinstruction at address 4.

The second row, at address 1, specifies a multiply-accumulateinstruction that instructs the 512 NPUs 126 to load a respective dataword from a row of the data RAM 122 and to load a respective weight wordfrom a row of the weight RAM 124, and to perform a firstmultiply-accumulate operation on the data word input 207 and weight wordinput 206, which is accumulated with the initialized accumulator 202zero value. More specifically, the instruction instructs the sequencer128 to generate a value on the control input 213 to select the data wordinput 207. In the example of FIG. 4, the specified data RAM 122 row isrow 17, and the specified weight RAM 124 row is row 0, which instructsthe sequencer 128 to output a data RAM address 123 value of 17 and tooutput a weight RAM address 125 value of 0. Consequently, the 512 datawords from row 17 of the data RAM 122 are provided to the correspondingdata input 207 of the 512 NPUs 126 and the 512 weight words from row 0of the weight RAM 124 are provided to the corresponding weight input 206of the 512 NPUs 126.

The third row, at address 2, specifies a multiply-accumulate rotateinstruction with a count of 511, which instructs each of the 512 NPUs126 to perform 511 multiply-accumulate operations. The instructioninstructs the 512 NPUs 126 that the data word 209 input to the ALU 204for each of the 511 multiply-accumulate operations is to be the rotatedvalue 211 from the adjacent NPU 126. That is, the instruction instructsthe sequencer 128 to generate a value on the control input 213 to selectthe rotated value 211. Additionally, the instruction instructs the 512NPUs 126 to load a respective weight word for each of the 511multiply-accumulate operations from the “next” row of the weight RAM124. That is, the instruction instructs the sequencer 128 to incrementthe weight RAM address 125 by one relative to its value in the previousclock cycle, which in the example would be row 1 on the first clockcycle of the instruction, row 2 on the next clock cycle, row 3 on thenext clock cycle, and so forth to row 511 on the 511^(th) clock cycle.For each of the 511 multiply-accumulate operations, the product of therotated input 211 and weight word input 206 is accumulated with theprevious value in the accumulator 202. The 512 NPUs 126 perform the 511multiply-accumulate operations in 511 clock cycles, in which each NPU126 performs a multiply-accumulate operation on a different data wordfrom row 17 of the data RAM 122—namely, the data word operated on by theadjacent NPU 126 in the previous cycle—and a different weight wordassociated with the data word, which is conceptually a differentconnection input to the neuron. In the example, it is assumed that thenumber of connection inputs to each NPU 126 (neuron) is 512, thusinvolving 512 data words and 512 weight words. Once the last iterationof the multiply-accumulate rotate instruction of row 2 is performed, theaccumulator 202 contains the sum of products for all 512 of theconnection inputs. In one embodiment, rather than having a separateinstruction for each type of ALU operation (e.g., multiply-accumulate,maximum of accumulator and weight word, etc. as described above), theNPU 126 instruction set includes an “execute” instruction that instructsthe ALU 204 to perform an ALU operation specified by the initialize NPUinstruction, such as specified in the ALU function 2926 of FIG. 29A.

The fourth row, at address 3, specifies an activation functioninstruction. The activation function instruction instructs the AFU 212to perform the specified activation function on the accumulator 202value 217 to generate the result 133. The activation functions accordingto one embodiment are described in more detail below.

The fifth row, at address 4, specifies a write AFU output instructionthat instructs the 512 NPUs 126 to write back their AFU 212 output asresults 133 to a row of the data RAM 122, which is row 16 in theexample. That is, the instruction instructs the sequencer 128 to outputa data RAM address 123 value of 16 and a write command (in contrast to aread command in the case of the multiply-accumulate instruction ataddress 1). Preferably the execution of the write AFU output instructionmay be overlapped with the execution of other instructions in apipelined nature such that the write AFU output instruction effectivelyexecutes in a single clock cycle.

Preferably, each NPU 126 is configured as a pipeline that includes thevarious functional elements, e.g., the mux-reg 208 (and mux-reg 705 ofFIG. 7), ALU 204, accumulator 202, AFU 212, mux 802 (of FIG. 8), rowbuffer 1104 and AFUs 1112 (of FIG. 11), etc., some of which maythemselves be pipelined. In addition to the data words 207 and weightwords 206, the pipeline receives the instructions from the programmemory 129. The instructions flow down the pipeline and control thevarious functional units. In an alternate embodiment, the activationfunction instruction is not included in the program. Rather, theinitialize NPU instruction specifies the activation function to beperformed on the accumulator 202 value 217, and a value indicating thespecified activation function is saved in a configuration register forlater use by the AFU 212 portion of the pipeline once the finalaccumulator 202 value 217 has been generated, i.e., once the lastiteration of the multiply-accumulate rotate instruction at address 2 hascompleted. Preferably, for power savings purposes, the AFU 212 portionof the pipeline is inactive until the write AFU output instructionreaches it, at which time the AFU 212 is powered up and performs theactivation function on the accumulator 202 output 217 specified by theinitialize instruction.

Referring now to FIG. 5, a timing diagram illustrating the execution ofthe program of FIG. 4 by the NNU 121 is shown. Each row of the timingdiagram corresponds to a successive clock cycle indicated in the firstcolumn. Each of the other columns corresponds to a different one of the512 NPUs 126 and indicates its operation. For simplicity and clarity ofillustration, the operations only for NPUs 0, 1 and 511 are shown.

At clock 0, each of the 512 NPUs 126 performs the initializationinstruction of FIG. 4, which is illustrated in FIG. 5 by the assignmentof a zero value to the accumulator 202.

At clock 1, each of the 512 NPUs 126 performs the multiply-accumulateinstruction at address 1 of FIG. 4. NPU 0 accumulates the accumulator202 value (which is zero) with the product of data RAM 122 row 17 word 0and weight RAM 124 row 0 word 0; NPU 1 accumulates the accumulator 202value (which is zero) with the product of data RAM 122 row 17 word 1 andweight RAM 124 row 0 word 1; and so forth to NPU 511 accumulates theaccumulator 202 value (which is zero) with the product of data RAM 122row 17 word 511 and weight RAM 124 row 0 word 511, as shown.

At clock 2, each of the 512 NPUs 126 performs a first iteration of themultiply-accumulate rotate instruction at address 2 of FIG. 4. NPU 0accumulates the accumulator 202 value with the product of the rotateddata word 211 received from the mux-reg 208 output 209 of NPU 511 (whichwas data word 511 received from the data RAM 122) and weight RAM 124 row1 word 0; NPU 1 accumulates the accumulator 202 value with the productof the rotated data word 211 received from the mux-reg 208 output 209 ofNPU 0 (which was data word 0 received from the data RAM 122) and weightRAM 124 row 1 word 1; and so forth to NPU 511 accumulates theaccumulator 202 value with the product of the rotated data word 211received from the mux-reg 208 output 209 of NPU 510 (which was data word510 received from the data RAM 122) and weight RAM 124 row 1 word 511,as shown.

At clock 3, each of the 512 NPUs 126 performs a second iteration of themultiply-accumulate rotate instruction at address 2 of FIG. 4. NPU 0accumulates the accumulator 202 value with the product of the rotateddata word 211 received from the mux-reg 208 output 209 of NPU 511 (whichwas data word 510 received from the data RAM 122) and weight RAM 124 row2 word 0; NPU 1 accumulates the accumulator 202 value with the productof the rotated data word 211 received from the mux-reg 208 output 209 ofNPU 0 (which was data word 511 received from the data RAM 122) andweight RAM 124 row 2 word 1; and so forth to NPU 511 accumulates theaccumulator 202 value with the product of the rotated data word 211received from the mux-reg 208 output 209 of NPU 510 (which was data word509 received from the data RAM 122) and weight RAM 124 row 2 word 511,as shown. As indicated by the ellipsis of FIG. 5, this continues foreach of the following 509 clock cycles until . . . .

At clock 512, each of the 512 NPUs 126 performs a 511^(th) iteration ofthe multiply-accumulate rotate instruction at address 2 of FIG. 4. NPU 0accumulates the accumulator 202 value with the product of the rotateddata word 211 received from the mux-reg 208 output 209 of NPU 511 (whichwas data word 1 received from the data RAM 122) and weight RAM 124 row511 word 0; NPU 1 accumulates the accumulator 202 value with the productof the rotated data word 211 received from the mux-reg 208 output 209 ofNPU 0 (which was data word 2 received from the data RAM 122) and weightRAM 124 row 511 word 1; and so forth to NPU 511 accumulates theaccumulator 202 value with the product of the rotated data word 211received from the mux-reg 208 output 209 of NPU 510 (which was data word0 received from the data RAM 122) and weight RAM 124 row 511 word 511,as shown. In one embodiment, multiple clock cycles are required to readthe data words and weight words from the data RAM 122 and weight RAM 124to perform the multiply-accumulate instruction at address 1 of FIG. 4;however, the data RAM 122 and weight RAM 124 and NPUs 126 are pipelinedsuch that once the first multiply-accumulate operation is begun (e.g.,as shown during clock 1 of FIG. 5), the subsequent multiply accumulateoperations (e.g., as shown during clocks 2-512) are begun in successiveclock cycles. Preferably, the NPUs 126 may briefly stall in response toan access of the data RAM 122 and/or weight RAM 124 by an architecturalinstruction, e.g., MTNN or MFNN instruction (described below withrespect to FIGS. 14 and 15) or a microinstruction into which thearchitectural instructions are translated.

At clock 513, the AFU 212 of each of the 512 NPUs 126 performs theactivation function instruction at address 3 of FIG. 4. Finally, atclock 514, each of the 512 NPUs 126 performs the write AFU outputinstruction at address 4 of FIG. 4 by writing back its result 133 to itscorresponding word of row 16 of the data RAM 122, i.e., the result 133of NPU 0 is written to word 0 of the data RAM 122, the result 133 of NPU1 is written to word 1 of the data RAM 122, and so forth to the result133 of NPU 511 is written to word 511 of the data RAM 122. The operationdescribed above with respect to FIG. 5 is also shown in block diagramform in FIG. 6A.

Referring now to FIG. 6A, a block diagram illustrating the NNU 121 ofFIG. 1 to execute the program of FIG. 4 is shown. The NNU 121 includesthe 512 NPUs 126, the data RAM 122 that receives its address input 123,and the weight RAM 124 that receives its address input 125. Although notshown, on clock 0 the 512 NPUs 126 perform the initializationinstruction. As shown, on clock 1, the 512 16-bit data words of row 17are read out of the data RAM 122 and provided to the 512 NPUs 126. Onclocks 1 through 512, the 512 16-bit weight words of rows 0 through 511,respectively, are read out of the weight RAM 124 and provided to the 512NPUs 126. Although not shown, on clock 1, the 512 NPUs 126 perform theirrespective multiply-accumulate operations on the loaded data words andweight words. On clocks 2 through 512, the mux-regs 208 of the 512 NPUs126 operate as a 512 16-bit word rotater to rotate the previously loadeddata words of row 17 of the data RAM 122 to the adjacent NPU 126, andthe NPUs 126 perform the multiply-accumulate operation on the respectiverotated data word and the respective weight word loaded from the weightRAM 124. Although not shown, on clock 513, the 512 AFUs 212 perform theactivation instruction. On clock 514, the 512 NPUs 126 write back theirrespective 512 16-bit results 133 to row 16 of the data RAM 122.

As may be observed, the number clocks required to generate the resultwords (neuron outputs) produced and written back to the data RAM 122 orweight RAM 124 is approximately the square root of the number of datainputs (connections) received by the current layer of the neuralnetwork. For example, if the currently layer has 512 neurons that eachhas 512 connections from the previous layer, the total number ofconnections is 256K and the number of clocks required to generate theresults for the current layer is slightly over 512. Thus, the NNU 121provides extremely high performance for neural network computations.

Referring now to FIG. 6B, a flowchart illustrating operation of theprocessor 100 of FIG. 1 to perform an architectural program that usesthe NNU 121 to perform multiply-accumulate-activation functioncomputations classically associated with neurons of hidden layers of anartificial neural network such as performed by the program of FIG. 4,for example. The example of FIG. 6B assumes computations for 4 hiddenlayers (signified by the initialization of the NUM_LAYERS variable atblock 602), each having 512 neurons each fully connected to 512 neuronsof the previous layer (by use of the program of FIG. 4). However, itshould be understood that these numbers of layers and neurons areselected for illustration purposes, and the NNU 121 may be employed toperform similar computations for different numbers of hidden layers anddifferent numbers of neurons per layer and for non-fully connectedneurons. In one embodiment, the weight values may be set to zero fornon-existent neurons in a layer or for non-existent connections to aneuron. Preferably, the architectural program writes a first set ofweights to the weight RAM 124 and starts the NNU 121, and while the NNU121 is performing the computations associated with the first layer, thearchitectural program writes a second set of weights to the weight RAM124 so that as soon as the NNU 121 completes the computations for thefirst hidden layer, the NNU 121 can start the computations for thesecond layer. In this manner, the architectural program ping-pongs backand forth between the two regions of the weight RAM 124 in order to keepthe NNU 121 fully utilized. Flow begins at block 602.

At block 602, the processor 100, i.e., the architectural program runningon the processor 100, writes the input values to the current hiddenlayer of neurons to the data RAM 122, e.g., into row 17 of the data RAM122, as shown and described with respect to FIG. 6A. Alternatively, thevalues may already be in row 17 of the data RAM 122 as results 133 ofthe operation of the NNU 121 for a previous layer (e.g., convolution,pooling or input layer). Additionally, the architectural programinitializes a variable N to a value of 1. The variable N denotes thecurrent layer of the hidden layers being processed by the NNU 121.Additionally, the architectural program initializes a variableNUM_LAYERS to a value of 4 since there are 4 hidden layers in theexample. Flow proceeds to block 604.

At block 604, the processor 100 writes the weight words for layer 1 tothe weight RAM 124, e.g., to rows 0 through 511, as shown in FIG. 6A.Flow proceeds to block 606.

At block 606, the processor 100 writes a multiply-accumulate-activationfunction program (e.g., of FIG. 4) to the NNU 121 program memory 129,using MTNN 1400 instructions that specify a function 1432 to write theprogram memory 129. The processor 100 then starts the NNU program usinga MTNN 1400 instruction that specifies a function 1432 to startexecution of the program. Flow proceeds to decision block 608.

At decision block 608, the architectural program determines whether thevalue of variable N is less than NUM_LAYERS. If so, flow proceeds toblock 612; otherwise, flow proceeds to block 614.

At block 612, the processor 100 writes the weight words for layer N+1 tothe weight RAM 124, e.g., to rows 512 through 1023. Thus,advantageously, the architectural program writes the weight words forthe next layer to the weight RAM 124 while the NNU 121 is performing thehidden layer computations for the current layer so that the NNU 121 canimmediately start performing the hidden layer computations for the nextlayer once the computations for the current layer are complete, i.e.,written to the data RAM 122. Flow proceeds to block 614.

At block 614, the processor 100 determines that the currently runningNNU program (started at block 606 in the case of layer 1, and started atblock 618 in the case of layers 2 through 4) has completed. Preferably,the processor 100 determines this by executing a MFNN 1500 instructionto read the NNU 121 status register 127. In an alternate embodiment, theNNU 121 generates an interrupt to indicate it has completed themultiply-accumulate-activation function layer program. Flow proceeds todecision block 616.

At decision block 616, the architectural program determines whether thevalue of variable N is less than NUM_LAYERS. If so, flow proceeds toblock 618; otherwise, flow proceeds to block 622.

At block 618, the processor 100 updates themultiply-accumulate-activation function program so that it can performthe hidden layer computations for layer N+1. More specifically, theprocessor 100 updates the data RAM 122 row value of themultiply-accumulate instruction at address 1 of FIG. 4 to the row of thedata RAM 122 to which the previous layer wrote its results (e.g., to row16) and also updates the output row (e.g., to row 15). The processor 100then starts the updated NNU program. Alternatively, the program of FIG.4 specifies the same row in the output instruction of address 4 as therow specified in the multiply-accumulate instruction at address 1 (i.e.,the row read from the data RAM 122). In this embodiment, the current rowof input data words is overwritten (which is acceptable as long as therow of data words is not needed for some other purpose, because the rowof data words has already been read into the mux-regs 208 and is beingrotated among the NPUs 126 via the N-word rotater). In this case, noupdate of the NNU program is needed at block 618, but only a re-start ofit. Flow proceeds to block 622.

At block 622, the processor 100 reads the results of the NNU programfrom the data RAM 122 for layer N. However, if the results are simply tobe used by the next layer, then the architectural program may not needto read the results from the data RAM 122, but instead leave them in thedata RAM 122 for the next hidden layer computations. Flow proceeds todecision block 624.

At decision block 624, the architectural program determines whether thevalue of variable N is less than NUM_LAYERS. If so, flow proceeds toblock 626; otherwise, flow ends.

At block 626, the architectural program increments N by one. Flowreturns to decision block 608.

As may be determined from the example of FIG. 6B, approximately every512 clock cycles, the NPUs 126 read once from and write once to the dataRAM 122 (by virtue of the operation of the NNU program of FIG. 4).Additionally, the NPUs 126 read the weight RAM 124 approximately everyclock cycle to read a row of the weight words. Thus, the entirebandwidth of the weight RAM 124 is consumed by the hybrid manner inwhich the NNU 121 performs the hidden layer operation. Additionally,assuming an embodiment that includes a write and read buffer such as thebuffer 1704 of FIG. 17, concurrently with the NPU 126 reads, theprocessor 100 writes the weight RAM 124 such that the buffer 1704performs one write to the weight RAM 124 approximately every 16 clockcycles to write the weight words. Thus, in a single-ported embodiment ofthe weight RAM 124 (such as described with respect to FIG. 17),approximately every 16 clock cycles, the NPUs 126 must be stalled fromreading the weight RAM 124 to enable the buffer 1704 to write the weightRAM 124. However, in an embodiment in which the weight RAM 124 isdual-ported, the NPUs 126 need not be stalled.

Referring now to FIG. 7, a block diagram illustrating a NPU 126 of FIG.1 according to an alternate embodiment is shown. The NPU 126 of FIG. 7is similar in many respects to the NPU 126 of FIG. 2. However, the NPU126 of FIG. 7 additionally includes a second 2-input mux-reg 705. Themux-reg 705 selects one of its inputs 206 or 711 to store in itsregister and then to provide on its output 203 on a subsequent clockcycle. Input 206 receives the weight word from the weight RAM 124. Theother input 711 receives the output 203 of the second mux-reg 705 of theadjacent NPU 126. Preferably, the mux-reg 705 input 711 of NPU Jreceives the mux-reg 705 output 203 of NPU 126 instance J−1, and theoutput of NPU J is provided to the mux-reg 705 input 711 of NPU 126instance J+1. In this manner, the mux-regs 705 of the N NPUs 126collectively operate as an N-word rotater, similar to the mannerdescribed above with respect to FIG. 3, but for the weight words ratherthan for the data words. A control input 713 controls which of the twoinputs the mux-reg 705 selects to store in its register and that issubsequently provided on the output 203.

Including the mux-regs 208 and/or mux-regs 705 (as well as the mux-regsof other embodiments, such as of FIGS. 18 and 23) to effectively form alarge rotater that rotates the data/weights of a row received from thedata RAM 122 and/or weight RAM 124 has an advantage that the NNU 121does not require an extremely large mux that would otherwise be requiredbetween the data RAM 122 and/or weight RAM 124 in order to provide thenecessary data/weight words to the appropriate NNU 121.

Writing Back Accumulator Values in Addition to Activation FunctionResult

In some applications, it is useful for the processor 100 to receive back(e.g., to the media registers 118 via the MFNN instruction of FIG. 15)the raw accumulator 202 value 217 upon which instructions executing onother execution units 112 can perform computations. For example, in oneembodiment, in order to reduce the complexity of the AFU 212, it is notconfigured to perform the softmax activation function. Consequently, theNNU 121 may output the raw accumulator 202 value 217, or a subsetthereof, to the data RAM 122 or weight RAM 124, which the architecturalprogram subsequently reads from the data RAM 122 or weight RAM 124 andperforms computations on the raw values. However, use of the rawaccumulator 202 value 217 is not limited to performance of softmax, andother uses are contemplated.

Referring now to FIG. 8, a block diagram illustrating a NPU 126 of FIG.1 according to an alternate embodiment is shown. The NPU 126 of FIG. 8is similar in many respects to the NPU 126 of FIG. 2. However, the NPU126 of FIG. 8 includes a multiplexer (mux) 802 in the AFU 212 that has acontrol input 803. The width (in bits) of the accumulator 202 is greaterthan the width of a data word. The mux 802 has multiple inputs thatreceive data word-width portions of the accumulator 202 output 217. Inone embodiment, the width of the accumulator 202 is 41 bits and the NPU126 is configured to output a result word 133 that is 16 bits; thus, forexample, the mux 802 (or mux 3032 and/or mux 3037 of FIG. 30) includesthree inputs that receive bits [15:0], bits [31:16], and bits [47:32] ofthe accumulator 202 output 217, respectively. Preferably, output bitsnot provided by the accumulator 202 (e.g., bits [47:41]) are forced tozero value bits.

The sequencer 128 generates a value on the control input 803 to controlthe mux 802 to select one of the words (e.g., 16 bits) of theaccumulator 202 in response to a write ACC instruction such as the writeACC instructions at addresses 3 through 5 of FIG. 9 described below.Preferably, the mux 802 also has one or more inputs that receive theoutput of activation function circuits (e.g., elements 3022, 3024, 3026,3018, 3014, and 3016 of FIG. 30) that generate outputs that are thewidth of a data word. The sequencer 128 generates a value on the controlinput 803 to control the mux 802 to select one of the activationfunction circuit outputs, rather than one of the words of theaccumulator 202, in response to an instruction such as the write AFUoutput instruction at address 4 of FIG. 4.

Referring now to FIG. 9, a table illustrating a program for storage inthe program memory 129 of and execution by the NNU 121 of FIG. 1 isshown. The example program of FIG. 9 is similar in many respects to theprogram of FIG. 4. Specifically, the instructions at addresses 0 through2 are identical. However, the instructions at addresses 3 and 4 of FIG.4 are replaced in FIG. 9 by write ACC instructions that instruct the 512NPUs 126 to write back their accumulator 202 output 217 as results 133to three rows of the data RAM 122, which is rows 16 through 18 in theexample. That is, the write ACC instruction instructs the sequencer 128to output a data RAM address 123 value of 16 and a write command in afirst clock cycle, to output a data RAM address 123 value of 17 and awrite command in a second clock cycle, and to output a data RAM address123 value of 18 and a write command in a third clock cycle. Preferablythe execution of the write ACC instruction may be overlapped with theexecution of other instructions such that the write ACC instructioneffectively executes in three clock cycles, one for each row written toin the data RAM 122. In one embodiment, the user specifies values of theactivation function 2934 and output command 2956 fields in the controlregister 127 (of FIG. 29A) to accomplish the writing of the desiredportions of the accumulator 202 to the data RAM 122 or weight RAM 124.Alternatively, rather than writing back the entire contents of theaccumulator 202, the write ACC instruction may optionally write back asubset of the accumulator 202. In one embodiment, a canonical form ofthe accumulator 202 may written back, as described in more detail belowwith respect to FIGS. 29 through 31.

Referring now to FIG. 10, a timing diagram illustrating the execution ofthe program of FIG. 9 by the NNU 121 is shown. The timing diagram ofFIG. 10 is similar to the timing diagram of FIG. 5, and clocks 0 through512 are the same. However, at clocks 513-515, the AFU 212 of each of the512 NPUs 126 performs one of the write ACC instructions at addresses 3through 5 of FIG. 9. Specifically, at clock 513, each of the 512 NPUs126 writes back as its result 133 to its corresponding word of row 16 ofthe data RAM 122 bits [15:0] of the accumulator 202 output 217; at clock514, each of the 512 NPUs 126 writes back as its result 133 to itscorresponding word of row 17 of the data RAM 122 bits [31:16] of theaccumulator 202 output 217; and at clock 515, each of the 512 NPUs 126writes back as its result 133 to its corresponding word of row 18 of thedata RAM 122 bits [40:32] of the accumulator 202 output 217. Preferably,bits [47:41] are forced to zero values.

Shared AFUs

Referring now to FIG. 11, a block diagram illustrating an embodiment ofthe NNU 121 of FIG. 1 is shown. In the embodiment of FIG. 11, a neuronis split into two portions, the activation function unit portion and theALU portion (which also includes the shift register portion), and eachactivation function unit portion is shared by multiple ALU portions. InFIG. 11, the ALU portions are referred to as NPUs 126 and the sharedactivation function unit portions are referred to as AFUs 1112. This isin contrast to the embodiment of FIG. 2, for example, in which eachneuron includes its own AFU 212. Hence, for example, in one embodimentthe NPUs 126 (ALU portions) of the embodiment of FIG. 11 include theaccumulator 202, ALU 204, mux-reg 208 and register 205 of FIG. 2, butnot the AFU 212. In the embodiment of FIG. 11, the NNU 121 includes 512NPUs 126 as an example; however, other embodiments with other numbers ofNPUs 126 are contemplated. In the example of FIG. 11, the 512 NPUs 126are grouped into 64 groups of eight NPUs 126 each, referred to as groups0 through 63 in FIG. 11.

The NNU 121 also includes a row buffer 1104 and a plurality of sharedAFUs 1112 coupled between the NPUs 126 and the row buffer 1104. The rowbuffer 1104 is the same width (in bits) as a row of the data RAM 122 orweight RAM 124, e.g., 512 words. There is one AFU 1112 per NPU 126group, i.e., each AFU 1112 has a corresponding NPU 126 group; thus, inthe embodiment of FIG. 11 there are 64 AFUs 1112 that correspond to the64 NPU 126 groups. Each of the eight NPUs 126 in a group shares thecorresponding AFU 1112. Other embodiments with different numbers of AFUs1112 and NPUs 126 per group are contemplated. For example, otherembodiments are contemplated in which two or four or sixteen NPUs 126 ina group share an AFU 1112.

A motivation for sharing AFUs 1112 is to reduce the size of the NNU 121.The size reduction is obtained at the cost of a performance reduction.That is, it may take several clocks longer, depending upon the sharingratio, to generate the results 133 for the entire array of NPUs 126, asdemonstrated in FIG. 12 below, for example, in which seven additionalclock cycles are required because of the 8:1 sharing ratio. However,generally speaking, the additional number of clocks (e.g., 7) isrelatively small compared to the number of clocks required to generatethe accumulated sum (e.g., 512 clocks for a layer that has 512connections per neuron). Hence, the relatively small performance impact(e.g., one percent increase in computation time) may be a worthwhiletradeoff for the reduced size of the NNU 121.

In one embodiment, each of the NPUs 126 includes an AFU 212 thatperforms relatively simple activation functions, thus enabling thesimple AFUs 212 to be relatively small and therefore included in eachNPU 126; whereas, the shared, or complex, AFUs 1112 perform relativelycomplex activation functions and are thus relatively significantlylarger than the simple AFUs 212. In such an embodiment, the additionalclock cycles are only required when a complex activation function isspecified that requires sharing of a complex AFU 1112, but not when anactivation function is specified that the simple AFU 212 is configuredto perform.

Referring now to FIGS. 12 and 13, two timing diagrams illustrating theexecution of the program of FIG. 4 by the NNU 121 of FIG. 11 is shown.The timing diagram of FIG. 12 is similar to the timing diagram of FIG.5, and clocks 0 through 512 are the same. However, at clock 513,operation is different than described in the timing diagram of FIG. 5because the NPUs 126 of FIG. 11 share the AFUs 1112; that is, the NPUs126 of a group share the AFU 1112 associated with the group, and FIG. 11illustrates the sharing.

Each row of the timing diagram of FIG. 13 corresponds to a successiveclock cycle indicated in the first column. Each of the other columnscorresponds to a different one of the 64 AFUs 1112 and indicates itsoperation. For simplicity and clarity of illustration, the operationsonly for AFUs 0, 1 and 63 are shown. The clock cycles of FIG. 13correspond to the clock cycles of FIG. 12 but illustrate the sharing ofthe AFUs 1112 by the NPUs 126 in a different manner. At clocks 0-512,each of the 64 AFUs 1112 is inactive, as shown in FIG. 13, while theNPUs 126 perform the initialize NPU and multiply-accumulate andmultiply-accumulate rotate instructions.

As shown in both FIGS. 12 and 13, at clock 513, AFU 0 (the AFU 1112associated with group 0) begins to perform the specified activationfunction on the accumulator 202 value 217 of NPU 0, which is the firstNPU 126 in group 0, and the output of AFU 0 will be stored to row buffer1104 word 0. Also at clock 513, each of the AFUs 1112 begins to performthe specified activation function on the accumulator 202 of the firstNPU 126 in its corresponding group of NPUs 126. Thus, in clock 513, asshown in FIG. 13, AFU 0 begins to perform the specified activationfunction on the accumulator 202 of NPU 0 to generate a result that willbe stored to row buffer 1104 word 0; AFU 1 begins to perform thespecified activation function on the accumulator 202 of NPU 8 togenerate a result that will be stored to row buffer 1104 word 8; and soforth to AFU 63 begins to perform the specified activation function onthe accumulator 202 of NPU 504 to generate a result that will be storedto row buffer 1104 word 504.

At clock 514, AFU 0 (the AFU 1112 associated with group 0) begins toperform the specified activation function on the accumulator 202 value217 of NPU 1, which is the second NPU 126 in group 0, and the output ofAFU 0 will be stored to row buffer 1104 word 1, as shown. Also at clock514, each of the AFUs 1112 begins to perform the specified activationfunction on the accumulator 202 of the second NPU 126 in itscorresponding group of NPUs 126. Thus, in clock 514, as shown in FIG.13, AFU 0 begins to perform the specified activation function on theaccumulator 202 of NPU 1 to generate a result that will be stored to rowbuffer 1104 word 1; AFU 1 begins to perform the specified activationfunction on the accumulator 202 of NPU 9 to generate a result that willbe stored to row buffer 1104 word 9; and so forth to AFU 63 begins toperform the specified activation function on the accumulator 202 of NPU505 to generate a result that will be stored to row buffer 1104 word505. This pattern continues until at clock cycle 520, AFU 0 (the AFU1112 associated with group 0) begins to perform the specified activationfunction on the accumulator 202 value 217 of NPU 7, which is the eighth(last) NPU 126 in group 0, and the output of AFU 0 will be stored to rowbuffer 1104 word 7, as shown. Also at clock 520, each of the AFUs 1112begins to perform the specified activation function on the accumulator202 of the eighth NPU 126 in its corresponding group of NPUs 126. Thus,in clock 520, as shown in FIG. 13, AFU 0 begins to perform the specifiedactivation function on the accumulator 202 of NPU 7 to generate a resultthat will be stored to row buffer 1104 word 7; AFU 1 begins to performthe specified activation function on the accumulator 202 of NPU 15 togenerate a result that will be stored to row buffer 1104 word 15; and soforth to AFU 63 begins to perform the specified activation function onthe accumulator 202 of NPU 511 to generate a result that will be storedto row buffer 1104 word 511.

At clock 521, once all 512 results associated with the 512 NPUs 126 havebeen generated and written to the row buffer 1104, the row buffer 1104begins to write its contents to the data RAM 122 or weight RAM 124. Inthis fashion, the AFU 1112 of each of the 64 groups of NPUs 126 performsa portion of the activation function instruction at address 3 of FIG. 4.

Embodiments such as that of FIG. 11 that share AFUs 1112 among groups ofALUs 204 may be particularly advantageous in conjunction with integerALUs 204, as described more below, e.g., with respect to FIGS. 29Athrough 33.

MTNN and MFNN Architectural Instructions

Referring now to FIG. 14, a block diagram illustrating a move to neuralnetwork (MTNN) architectural instruction 1400 and its operation withrespect to portions of the NNU 121 of FIG. 1 is shown. The MTNNinstruction 1400 includes an opcode field 1402, a src1 field 1404, asrc2 field 1406, a gpr field 1408, and an immediate field 1412. The MTNNinstruction 1400 is an architectural instruction, i.e., it is includedin the instruction set architecture of the processor 100. Preferably,the instruction set architecture associates a predetermined value of theopcode field 1402 with the MTNN instruction 1400 to distinguish it fromother instructions in the instruction set architecture. The MTNNinstruction 1400 opcode 1402 may or may not include prefixes, such asare common, for example, in the x86 architecture.

The immediate field 1412 provides a value that specifies a function 1432to control logic 1434 of the NNU 121. Preferably, the function 1432 isprovided as an immediate operand of a microinstruction 105 of FIG. 1.The functions 1432 that may be performed by the NNU 121 include, but arenot limited to, writing to the data RAM 122, writing to the weight RAM124, writing to the program memory 129, writing to the control register127, starting execution of a program in the program memory 129, pausingthe execution of a program in the program memory 129, requestnotification (e.g., interrupt) of completion of the execution of aprogram in the program memory 129, and resetting the NNU 121.Preferably, the NNU instruction set includes an instruction whose resultindicates the NNU program is complete. Alternatively, the NNUinstruction set includes an explicit generate interrupt instruction.Preferably, resetting the NNU 121 includes effectively forcing the NNU121 back to a reset state (e.g., internal state machines are cleared andset to an idle state), except the contents of the data RAM 122, weightRAM 124, program memory 129 are left intact. Additionally, internalregisters such as the accumulator 202 are not affected by the resetfunction and must be explicitly cleared, e.g., by an initialize NPUinstruction at address 0 of FIG. 4. In one embodiment, the function 1432may include a direct execution function in which the first sourceregister contains a micro-operation (see for example micro-operation3418 of FIG. 34). The direct execution function instructs the NNU 121 todirectly execute the specified micro-operation. In this manner, anarchitectural program may directly control the NNU 121 to performoperations, rather than writing instructions to the program memory 129and then instructing the NNU 121 to execute the instructions in theprogram memory or by executing an MTNN instruction 1400 (or an MFNNinstruction 1500 of FIG. 15). FIG. 14 illustrates an example of thefunction 1432 of writing to the data RAM 122.

The gpr field 1408 specifies one of the GPR in the general purposeregister file 116. In one embodiment, each GPR is 64 bits. The generalpurpose register file 116 provides the value from the selected GPR tothe NNU 121, as shown, which uses the value as an address 1422. Theaddress 1422 selects a row of the memory specified in the function 1432.In the case of the data RAM 122 or weight RAM 124, the address 1422additionally selects a chunk that is twice the size of a media register(e.g., 512 bits) location within the selected row. Preferably, thelocation is on a 512-bit boundary. In one embodiment, a multiplexerselects either the address 1422 (or address 1422 in the case of a MFNNinstruction 1400 described below) or the address 123/125/131 from thesequencer 128 for provision to the data RAM 122/weight RAM 124/programmemory 129. In one embodiment, as described in more detail below, thedata RAM 122 is dual-ported to allow the NPUs 126 to read/write the dataRAM 122 concurrently with the media registers 118 reading/writing thedata RAM 122. In one embodiment, the weight RAM 124 is also dual-portedfor a similar purpose.

The src1 field 1404 and src2 field 1406 each specify a media register inthe media register file 118. In one embodiment, each media register 118is 256 bits. The media register file 118 provides the concatenated data(e.g., 512 bits) from the selected media registers to the data RAM 122(or weight RAM 124 or program memory 129) for writing into the selectedrow 1428 specified by the address 1422 and into the location specifiedby the address 1422 within the selected row 1428, as shown.Advantageously, by executing a series of MTNN instructions 1400 (andMFNN instructions 1400 described below), an architectural programexecuting on the processor 100 can populate rows of the data RAM 122 androws of the weight RAM 124 and write a program to the program memory129, such as the programs described herein (e.g., of FIGS. 4 and 9) tocause the NNU 121 to perform operations on the data and weights atextremely high speeds to accomplish an artificial neural network. In oneembodiment, the architectural program directly controls the NNU 121rather than writing a program into the program memory 129.

In one embodiment, rather than specifying two source registers (e.g.,1404 and 1406), the MTNN instruction 1400 specifies a start sourceregister and a number of source registers, Q. This form of the MTNNinstruction 1400 instructs the processor 100 to write the media register118 specified as the start source register as well as the next Q-1sequential media registers 118 to the NNU 121, i.e., to the data RAM 122or weight RAM 124 specified. Preferably, the instruction translator 104translates the MTNN instruction 1400 into as many microinstructions asneeded to write all the Q specified media registers 118. For example, inone embodiment, when the MTNN instruction 1400 specifies a start sourceregister as MR4 and Q is 8, then the instruction translator 104translates the MTNN instruction 1400 into four microinstructions, thefirst of which writes MR4 and MR5, the second of which writes MR6 andMR7, the third of which writes MR8 and MR9, and the fourth of whichwrites MR10 and MR11. In an alternate embodiment in which the data pathfrom the media registers 118 to the NNU 121 is 1024 bits rather than512, the instruction translator 104 translates the MTNN instruction 1400into two microinstructions, the first of which writes MR4 through MR7,and the second of which writes MR8 through MR11. A similar embodiment iscontemplated in which the MFNN instruction 1500 specifies a startdestination register and a number of destination registers, to enablereading larger chunks of a row of the data RAM 122 or weight RAM 124 perMFNN instruction 1500 than a single media register 118.

Referring now to FIG. 15, a block diagram illustrating a move fromneural network (MFNN) architectural instruction 1500 and its operationwith respect to portions of the NNU 121 of FIG. 1 is shown. The MFNNinstruction 1500 includes an opcode field 1502, a dst field 1504, a gprfield 1508, and an immediate field 1512. The MFNN instruction 1500 is anarchitectural instruction, i.e., it is included in the instruction setarchitecture of the processor 100. Preferably, the instruction setarchitecture associates a predetermined value of the opcode field 1502with the MFNN instruction 1500 to distinguish it from other instructionsin the instruction set architecture. The MFNN instruction 1500 opcode1502 may or may not include prefixes, such as are common, for example,in the x86 architecture.

The immediate field 1512 provides a value that specifies a function 1532to the control logic 1434 of the NNU 121. Preferably, the function 1532is provided as an immediate operand of a microinstruction 105 of FIG. 1.The functions 1532 that may be performed by the NNU 121 include, but arenot limited to, reading from the data RAM 122, reading from the weightRAM 124, reading from the program memory 129, and reading from thestatus register 127. FIG. 15 illustrates an example of the function 1532of reading from the data RAM 122.

The gpr field 1508 specifies one of the GPR in the general purposeregister file 116. The general purpose register file 116 provides thevalue from the selected GPR to the NNU 121, as shown, which uses thevalue as an address 1522 that operates in a manner similar to theaddress 1422 of FIG. 14 to select a row of the memory specified in thefunction 1532 and, in the case of the data RAM 122 or weight RAM 124,the address 1522 additionally selects a chunk that is the size of amedia register (e.g., 256 bits) location within the selected row.Preferably, the location is on a 256-bit boundary.

The dst field 1504 specifies a media register in the media register file118. The media register file 118 receives the data (e.g., 256 bits) intothe selected media register from the data RAM 122 (or weight RAM 124 orprogram memory 129) read from the selected row 1528 specified by theaddress 1522 and from the location specified by the address 1522 withinthe selected row 1528, as shown.

NNU Internal RAM Port Configurations

Referring now to FIG. 16, a block diagram illustrating an embodiment ofthe data RAM 122 of FIG. 1 is shown. The data RAM 122 includes a memoryarray 1606, a read port 1602 and a write port 1604. The memory array1606 holds the data words and is preferably arranged as D rows of Nwords, as described above. In one embodiment, the memory array 1606comprises an array of 64 horizontally arranged static RAM cells in whicheach cell is 128 bits wide and 64 tall to provide a 64 KB data RAM 122that is 8192 bits wide and has 64 rows, and the data RAM 122 occupiesapproximately 0.2 square millimeters of die area. However, otherembodiments are contemplated.

The read port 1602 is coupled, preferably in a multiplexed fashion, tothe NPUs 126 and to the media registers 118. (More precisely, the mediaregisters 118 may be coupled to the read port 1602 via result bussesthat may also provide data to a reorder buffer and/or result forwardingbusses to the other execution units 112). The NPUs 126 and mediaregisters 118 share the read port 1602 to read the data RAM 122. Thewrite port 1604 is also coupled, preferably in a multiplexed fashion, tothe NPUs 126 and to the media registers 118. The NPUs 126 and mediaregisters 118 shared the write port 1604 to write the data RAM 122.Thus, advantageously, the media registers 118 can concurrently write tothe data RAM 122 while the NPUs 126 are also reading from the data RAM122, or the NPUs 126 can concurrently write to the data RAM 122 whilethe media registers 118 are reading from the data RAM 122. This mayadvantageously provide improved performance. For example, the NPUs 126can read the data RAM 122 (e.g., to continue to perform calculations)while the media registers 118 write more data words to the data RAM 122.For another example, the NPUs 126 can write calculation results to thedata RAM 122 while the media registers 118 read calculation results fromthe data RAM 122. In one embodiment, the NPUs 126 can write a row ofcalculation results to the data RAM 122 while the NPUs 126 also read arow of data words from the data RAM 122. In one embodiment, the memoryarray 1606 is configured in banks. When the NPUs 126 access the data RAM122, all of the banks are activated to access an entire row of thememory array 1606; whereas, when the media registers 118 access the dataRAM 122, only the specified banks are activated. In one embodiment, eachbank is 128 bits wide and the media registers 118 are 256 bits wide,hence two banks are activated per media register 118 access, forexample. In one embodiment, one of the ports 1602/1604 is a read/writeport. In one embodiment, both the ports 1602 and 1604 are read/writeports.

An advantage of the rotater capability of the NPUs 126 as describedherein is that it facilitates the ability for the memory array 1606 ofthe data RAM 122 to have significantly fewer rows, and therefore berelatively much smaller, than might otherwise be needed in order toinsure that the NPUs 126 are highly utilized, which requires thearchitectural program (via the media registers 118) to be able tocontinue to provide data to the data RAM 122 and to retrieve resultsfrom it while the NPUs 126 are performing computations.

Internal RAM Buffer

Referring now to FIG. 17, a block diagram illustrating an embodiment ofthe weight RAM 124 of FIG. 1 and a buffer 1704 is shown. The weight RAM124 includes a memory array 1706 and a port 1702. The memory array 1706holds the weight words and is preferably arranged as W rows of N words,as described above. In one embodiment, the memory array 1706 comprisesan array of 128 horizontally arranged static RAM cells in which eachcell is 64 bits wide and 2048 tall to provide a 2 MB weight RAM 124 thatis 8192 bits wide and has 2048 rows, and the weight RAM 124 occupiesapproximately 2.4 square millimeters of die area. However, otherembodiments are contemplated.

The port 1702 is coupled, preferably in a multiplexed fashion, to theNPUs 126 and to the buffer 1704. The NPUs 126 and buffer 1704 read andwrite the weight RAM 124 via the port 1702. The buffer 1704 is alsocoupled to the media registers 118 of FIG. 1 such that the mediaregisters 118 read and write the weight RAM 124 through the buffer 1704.Thus, advantageously, the media registers 118 can concurrently write toor read from the buffer 1704 while the NPUs 126 are also reading from orwriting to the weight RAM 124 (although preferably the NPUs 126 stall,if they are currently executing, to avoid accessing the weight RAM 124while the buffer 1704 is accessing the weight RAM 124). This mayadvantageously provide improved performance, particularly since thereads/writes by the media registers 118 to the weight RAM 124 arerelatively much smaller than the reads/writes by the NPUs 126 to theweight RAM 124. For example, in one embodiment, the NPUs 126 read/write8192 bits (one row) at a time, whereas the media registers 118 are 256bits wide, and each MTNN instructions 1400 writes two media registers118, i.e., 512 bits. Thus, in the case where the architectural programexecutes sixteen MTNN instructions 1400 to populate the buffer 1704, aconflict occurs between the NPUs 126 and the architectural program foraccess to the weight RAM 124 only less than approximately six percent ofthe time. In an alternate embodiment, the instruction translator 104translates a MTNN instruction 1400 into two microinstructions 105, eachof which writes a single media register 118 to the buffer 1704, in whichcase a conflict occurs between the NPUs 126 and the architecturalprogram for access to the weight RAM 124 even less frequently.

In one embodiment that includes the buffer 1704, writing to the weightRAM 124 by an architectural program requires multiple MTNN instructions1400. One or more MTNN instructions 1400 specify a function 1432 towrite to specified chunks of the buffer 1704 followed by an MTNNinstruction 1400 that specifies a function 1432 that instructs the NNU121 to write the contents of the buffer 1704 to a specified row of theweight RAM 124, where the size of a chunk is twice the number of bits ofa media register 118 and chunks are naturally aligned within the buffer1704. In one embodiment, in each of the MTNN instructions 1400 thatspecify a function 1432 to write to specified chunks of the buffer 1704,a bitmask is included that has a bit corresponding to each chunk of thebuffer 1704. The data from the two specified source registers 118 iswritten to each chunk of the buffer 1704 whose corresponding bit in thebitmask is set. This may be useful for repeated data values within a rowof the weight RAM 124. For example, in order to zero out the buffer 1704(and subsequently a row of the weight RAM 124), the programmer may loadthe source registers with zero and set all bits of the bitmask.Additionally, the bitmask enables the programmer to only write toselected chunks of the buffer 1704 and thereby retain the previous datain the other chunks.

In one embodiment that includes the buffer 1704, reading from the weightRAM 124 by an architectural program requires multiple MFNN instructions1500. An initial MFNN instruction 1500 specifies a function 1532 to loadthe buffer 1704 from a specified row of the weight RAM 124 followed byone or more MFNN instructions 1500 that specify a function 1532 to reada specified chunk of the buffer 1704 into the destination register,where the size of a chunk is the number of bits of a media register 118and chunks are naturally aligned within the buffer 1704. Otherembodiments are contemplated in which the weight RAM 124 includesmultiple buffers 1704 to further reduce contention between the NPUs 126and the architectural program for access to the weight RAM 124 byincreasing the number of accesses that can be made by the architecturalprogram while the NPUs 126 are executing, which may increase thelikelihood that the accesses by the buffers 1704 can be performed duringclock cycles in which the NPUs 126 do not need to access the weight RAM124.

Although FIG. 16 describes a dual-ported data RAM 122, other embodimentsare contemplated in which the weight RAM 124 is also dual-ported.Furthermore, although FIG. 17 describes a buffer for use with the weightRAM 124, other embodiments are contemplated in which the data RAM 122also has an associated buffer similar to buffer 1704.

Dynamically Configurable NPUs

Referring now to FIG. 18, a block diagram illustrating a dynamicallyconfigurable NPU 126 of FIG. 1 is shown. The NPU 126 of FIG. 18 issimilar in many respects to the NPU 126 of FIG. 2. However, the NPU 126of FIG. 18 is dynamically configurable to operate in one of twodifferent configurations. In a first configuration, the NPU 126 of FIG.18 operates similar to the NPU 126 of FIG. 2. That is, in the firstconfiguration, referred to herein as “wide” configuration or “single”configuration, the ALU 204 of the NPU 126 performs operations on asingle wide data word and a single wide weight word (e.g., 16 bits) togenerate a single wide result. In contrast, in the second configuration,referred to herein as “narrow” configuration or “dual” configuration,the NPU 126 performs operations on two narrow data words and tworespective narrow weight words (e.g., 8 bits) to generate two respectivenarrow results. In one embodiment, the configuration (wide or narrow) ofthe NPU 126 is made by the initialize NPU instruction (e.g., at address0 of FIG. 20, described below). Alternatively, the configuration is madeby an MTNN instruction whose function 1432 specifies to configure theNPU 126 to the configuration (wide or narrow). Preferably, configurationregisters are populated by the program memory 129 instruction or theMTNN instruction that determine the configuration (wide or narrow). Forexample, the configuration register outputs are provided to the ALU 204,AFU 212 and logic that generates the mux-reg control signal 213.Generally speaking, the elements of the NPUs 126 of FIG. 18 performsimilar functions to their like-numbered elements of FIG. 2 andreference should be made thereto for an understanding of FIG. 18.However, the embodiment of FIG. 18 will now be described, includingdifferences from FIG. 2.

The NPU 126 of FIG. 18 includes two registers 205A and 205B, two 3-inputmux-regs 208A and 208B, an ALU 204, two accumulators 202A and 202B, andtwo AFUs 212A and 212B. Each of the registers 205A/205B is separatelyhalf the width (e.g., 8 bits) of register 205 of FIG. 2. Each of theregisters 205A/205B receives a respective narrow weight word 206A/206B(e.g., 8 bits) from the weight RAM 124 and provides its output 203A/203Bon a subsequent clock cycle to operand selection logic 1898 of the ALU204. When the NPU 126 is in a wide configuration, the registers205A/205B effectively function together to receive a wide weight word206A/206B (e.g., 16 bits) from the weight RAM 124, similar to the mannerof the register 205 of the embodiment of FIG. 2; and when the NPU 126 isin a narrow configuration, the registers 205A/205B effectively functionindividually to each receive a narrow weight word 206A/206B (e.g., 8bits) from the weight RAM 124 such that the NPU 126 is effectively twoseparate narrow NPUs. Nevertheless, the same output bits of the weightRAM 124 are coupled to and provided to the registers 205A/205B,regardless of the configuration of the NPU 126. For example, theregister 205A of NPU 0 receives byte 0, the register 205B of NPU 0receives byte 1, the register 205A of NPU 1 receives byte 2, theregister 205B of NPU 1 receives byte 3, and so forth to the register205B of NPU 511 receives byte 1023.

Each of the mux-regs 208A/208B is separately half the width (e.g., 8bits) of register 208 of FIG. 2. The mux-reg 208A selects one of itsinputs 207A or 211A or 1811A to store in its register and then toprovide on its output 209A on a subsequent clock cycle, and the mux-reg208B selects one of its inputs 207B or 211B or 1811B to store in itsregister and then to provide on its output 209B on a subsequent clockcycle to the operand selection logic 1898. The input 207A receives anarrow data word (e.g., 8 bits) from the data RAM 122, and the input207B receives a narrow data word from the data RAM 122. When the NPU 126is in a wide configuration, the mux-regs 208A/208B effectively functiontogether to receive a wide data word 207A/207B (e.g., 16 bits) from thedata RAM 122, similar to the manner of the mux-reg 208 of the embodimentof FIG. 2; and when the NPU 126 is in a narrow configuration, themux-regs 208A/208B effectively function individually to each receive anarrow data word 207A/207B (e.g., 8 bits) from the data RAM 122 suchthat the NPU 126 is effectively two separate narrow NPUs. Nevertheless,the same output bits of the data RAM 122 are coupled to and provided tothe mux-regs 208A/208B, regardless of the configuration of the NPU 126.For example, the mux-reg 208A of NPU 0 receives byte 0, the mux-reg 208Bof NPU 0 receives byte 1, the mux-reg 208A of NPU 1 receives byte 2, themux-reg 208B of NPU 1 receives byte 3, and so forth to the mux-reg 208Bof NPU 511 receives byte 1023.

The input 211A receives the output 209A of mux-reg 208A of the adjacentNPU 126, and the input 211B receives the output 209B of mux-reg 208B ofthe adjacent NPU 126. The input 1811A receives the output 209B ofmux-reg 208B of the adjacent NPU 126, and the input 1811B receives theoutput 209A of mux-reg 208A of the instant NPU 126, as shown. The NPU126 shown in FIG. 18 is denoted NPU J from among the N NPUs 126 ofFIG. 1. That is, NPU J is a representative instance of the N NPUs 126.Preferably, the mux-reg 208A input 211A of NPU J receives the mux-reg208A output 209A of NPU 126 instance J−1, the mux-reg 208A input 1811Aof NPU J receives the mux-reg 208B output 209B of NPU 126 instance J−1,and the mux-reg 208A output 209A of NPU J is provided both to themux-reg 208A input 211A of NPU 126 instance J+1 and to the mux-reg 208Binput 211B of NPU 126 instance J; and the mux-reg 208B input 211B of NPUJ receives the mux-reg 208B output 209B of NPU 126 instance J−1, themux-reg 208B input 1811B of NPU J receives the mux-reg 208A output 209Aof NPU 126 instance J, and the mux-reg 208B output 209B of NPU J isprovided to both the mux-reg 208A input 1811A of NPU 126 instance J+1and to the mux-reg 208B input 211B of NPU 126 instance J+1.

The control input 213 controls which of the three inputs each of themux-regs 208A/208B selects to store in its respective register and thatis subsequently provided on the respective outputs 209A/209B. When theNPU 126 is instructed to load a row from the data RAM 122 (e.g., as bythe multiply-accumulate instruction at address 1 of FIG. 20, describedbelow), regardless of whether the NPU 126 is in a wide or narrowconfiguration, the control input 213 controls each of the mux-regs208A/208B to select a respective narrow data word 207A/207B (e.g., 8bits) from the corresponding narrow word of the selected row of the dataRAM 122.

When the NPU 126 is instructed to rotate the previously received datarow values (e.g., as by the multiply-accumulate rotate instruction ataddress 2 of FIG. 20, described below), if the NPU 126 is in a narrowconfiguration, the control input 213 controls each of the mux-regs208A/208B to select the respective input 1811A/1811B. In this case, themux-regs 208A/208B function individually effectively such that the NPU126 is effectively two separate narrow NPUs. In this manner, themux-regs 208A and 208B of the N NPUs 126 collectively operate as a2N-narrow-word rotater, as described in more detail below with respectto FIG. 19.

When the NPU 126 is instructed to rotate the previously received datarow values, if the NPU 126 is in a wide configuration, the control input213 controls each of the mux-regs 208A/208B to select the respectiveinput 211A/211B. In this case, the mux-regs 208A/208B function togethereffectively as if the NPU 126 is a single wide NPU 126. In this manner,the mux-regs 208A and 208B of the N NPUs 126 collectively operate as anN-wide-word rotater, similar to the manner described with respect toFIG. 3.

The ALU 204 includes the operand selection logic 1898, a wide multiplier242A, a narrow multiplier 242B, a wide two-input mux 1896A, a narrowtwo-input mux 1896B, a wide adder 244A and a narrow adder 244B.Effectively, the ALU 204 comprises the operand selection logic 1898, awide ALU 204A (comprising the wide multiplier 242A, the wide mux 1896Aand the wide adder 244A) and a narrow ALU 204B (comprising the narrowmultiplier 242B, the narrow mux 1896B and the narrow adder 244B).Preferably, the wide multiplier 242A multiplies two wide words and issimilar to the multiplier 242 of FIG. 2, e.g., a 16-bit by 16-bitmultiplier. The narrow multiplier 242B multiplies two narrow words,e.g., an 8-bit by 8-bit multiplier that generates a 16-bit result. Whenthe NPU 126 is in a narrow configuration, the wide multiplier 242A iseffectively used, with the help of the operand selection logic 1898, asa narrow multiplier to multiply two narrow words so that the NPU 126effectively functions as two narrow NPUs. Preferably, the wide adder244A adds the output of the wide mux 1896A and the wide accumulator 202Aoutput 217A to generate a sum 215A for provision to the wide accumulator202A and is similar to the adder 244 of FIG. 2. The narrow adder 244Badds the output of the narrow mux 1896B and the narrow accumulator 202Boutput 217B to generate a sum 215B for provision to the narrowaccumulator 202B. In one embodiment, the narrow accumulator 202B is 28bits wide to avoid loss of precision in the accumulation of up to 102416-bit products. When the NPU 126 is in a wide configuration, the narrowmultiplier 242B, narrow mux 1896B, narrow adder 244B, narrow accumulator202B and narrow AFU 212B are preferably inactive to reduce powerconsumption.

The operand selection logic 1898 selects operands from 209A, 209B, 203Aand 203B to provide to the other elements of the ALU 204, as describedin more detail below. Preferably, the operand selection logic 1898 alsoperforms other functions, such as performing sign extension ofsigned-valued data words and weight words. For example, if the NPU 126is in a narrow configuration, the operand selection logic 1898 signextends the narrow data word and weight word to the width of a wide wordbefore providing them to the wide multiplier 242A. Similarly, if the ALU204 is instructed to pass through a narrow data/weight word (bypass thewide multiplier 242A via wide mux 1896A), the operand selection logic1898 sign extends the narrow data/weight word to the width of a wideword before providing it to the wide adder 244A. Preferably, logic isalso present in the ALU 204 of the NPU 126 of FIG. 2 to perform thesign-extension function.

The wide mux 1896A receives the output of the wide multiplier 242A andan operand from the operand selection logic 1898 and selects one of theinputs for provision to the wide adder 244A, and the narrow mux 1896Breceives the output of the narrow multiplier 242B and an operand fromthe operand selection logic 1898 and selects one of the inputs forprovision to the narrow adder 244B.

The operands provided by the operand selection logic 1898 depend uponthe configuration of the NPU 126 and upon the arithmetic and/or logicaloperations to be performed by the ALU 204 based on the functionspecified by the instruction being executed by the NPU 126. For example,if the instruction instructs the ALU 204 to perform amultiply-accumulate and the NPU 126 is in a wide configuration, theoperand selection logic 1898 provides to the wide multiplier 242A on oneinput a wide word that is the concatenation of outputs 209A and 209B andon the other input a wide word that is the concatenation of outputs 203Aand 203B, and the narrow multiplier 242B is inactive, so that the NPU126 functions as a single wide NPU 126 similar to the NPU 126 of FIG. 2.Whereas, if the instruction instructs the ALU 204 to perform amultiply-accumulate and the NPU 126 is in a narrow configuration, theoperand selection logic 1898 provides to the wide multiplier 242A on oneinput an extended, or widened, version of the narrow data word 209A andon the other input an extended version of the narrow weight word 203A;additionally, the operand selection logic 1898 provides to the narrowmultiplier 242B on one input the narrow data words 209B and on the otherinput the narrow weight word 203B. To extend, or widen, a narrow word,if the narrow word is signed, then the operand selection logic 1898sign-extends the narrow word, whereas if the narrow word is unsigned,the operand selection logic 1898 pads the narrow word with zero-valuedupper bits

For another example, if the NPU 126 is in a wide configuration and theinstruction instructs the ALU 204 to perform an accumulate of the weightword, the wide multiplier 242A is bypassed and the operand selectionlogic 1898 provides the concatenation of outputs 203A and 203B to thewide mux 1896A for provision to the wide adder 244A. Whereas, if the NPU126 is in a narrow configuration and the instruction instructs the ALU204 to perform an accumulate of the weight word, the wide multiplier242A is bypassed and the operand selection logic 1898 provides anextended version of the output 203A to the wide mux 1896A for provisionto the wide adder 244A; and the narrow multiplier 242B is bypassed andthe operand selection logic 1898 provides an extended version of theoutput 203B to the narrow mux 1896B for provision to the narrow adder244B.

For another example, if the NPU 126 is in a wide configuration and theinstruction instructs the ALU 204 to perform an accumulate of the dataword, the wide multiplier 242A is bypassed and the operand selectionlogic 1898 provides the concatenation of outputs 209A and 209B to thewide mux 1896A for provision to the wide adder 244A. Whereas, if the NPU126 is in a narrow configuration and the instruction instructs the ALU204 to perform an accumulate of the data word, the wide multiplier 242Ais bypassed and the operand selection logic 1898 provides an extendedversion of the output 209A to the wide mux 1896A for provision to thewide adder 244A; and the narrow multiplier 242B is bypassed and theoperand selection logic 1898 provides an extended version of the output209B to the narrow mux 1896B for provision to the narrow adder 244B. Theaccumulation of weight/data words may be useful for performing averagingoperations that are used in pooling layers of some artificial neuralnetwork applications, such as image processing.

Preferably, the NPU 126 also includes a second wide mux (not shown) forbypassing the wide adder 244A to facilitate loading the wide accumulator202A with a wide data/weight word in wide configuration or an extendednarrow data/weight word in narrow configuration, and a second narrow mux(not shown) for bypassing the narrow adder 244B to facilitate loadingthe narrow accumulator 202B with a narrow data/weight word in narrowconfiguration. Preferably, the ALU 204 also includes wide and narrowcomparator/mux combinations (not shown) that receive the respectiveaccumulator value 217A/217B and respective mux 1896A/1896B output toselect the maximum value between the accumulator value 217A/217B and adata/weight word 209A/B/203A/B, an operation that is used in poolinglayers of some artificial neural network applications, as described inmore detail below, e.g., with respect to FIGS. 27 and 28. Additionally,the operand selection logic 1898 is configured to provide zero-valuedoperands (for addition with zero or for clearing the accumulators) andto provide one-valued operands (for multiplication by one).

The narrow AFU 212B receives the output 217B of the narrow accumulator202B and performs an activation function on it to generate a narrowresult 133B, and the wide AFU 212A receives the output 217A of the wideaccumulator 202A and performs an activation function on it to generate awide result 133A. When the NPU 126 is in a narrow configuration, thewide AFU 212A considers the output 217A of the wide accumulator 202Aaccordingly and performs an activation function on it to generate anarrow result, e.g., 8 bits, as described in more detail below withrespect to FIGS. 29A through 30, for example.

As may observed from the above description, advantageously the singleNPU 126 operates effectively as two narrow NPUs when in a narrowconfiguration, thus providing, for smaller words, approximately up totwice the throughput as when in the wide configuration. For example,assume a neural network layer having 1024 neurons each receiving 1024narrow inputs from the previous layer (and having narrow weight words),resulting in 1 Mega-connections. An NNU 121 having 512 NPUs 126 in anarrow configuration (1024 narrow NPU) compared to an NNU 121 having 512NPUs 126 in a wide configuration is capable of processing four times thenumber of connections (1 Mega-connections vs. 256K connections) inapproximately half the time (approx. 1026 clocks vs. 514 clocks), albeitfor narrow words rather than wide words.

In one embodiment, the dynamically configurable NPU 126 of FIG. 18includes 3-input multiplexed-registers similar to mux-regs 208A and 208Bin place of the registers 205A and 205B to accomplish a rotater for arow of weight words received from the weight RAM 124 somewhat similar tothe manner described with respect to the embodiment of FIG. 7 but in adynamically configurable fashion as described with respect to FIG. 18.

Referring now to FIG. 19, a block diagram illustrating an embodiment ofthe arrangement of the 2N mux-regs 208A/208B of the N NPUs 126 of theNNU 121 of FIG. 1 according to the embodiment of FIG. 18 to illustratetheir operation as a rotater for a row of data words 207 received fromthe data RAM 122 of FIG. 1 is shown. In the embodiment of FIG. 19, N is512 such that the NNU 121 has 1024 mux-regs 208A/208B, denoted 0 through511, corresponding to 512 NPUs 126 and effectively 1024 narrow NPUs, asshown. The two narrow NPUs within a NPU 126 are denoted A and B, andwithin each of the mux-regs 208, the designation of the correspondingnarrow NPU is shown. More specifically, mux-reg 208A of NPU 126 0 isdesignated 0-A, mux-reg 208B of NPU 126 0 is designated 0-B, mux-reg208A of NPU 126 1 is designated 1-A, mux-reg 208B of NPU 126 1 isdesignated 1-B, mux-reg 208A of NPU 126 511 is designated 511-A, andmux-reg 208B of NPU 126 511 is designated 0-B, which values alsocorrespond to the narrow NPUs of FIG. 21 described below.

Each mux-reg 208A receives its corresponding narrow data word 207A ofone row of the D rows of the data RAM 122, and each mux-reg 208Breceives its corresponding narrow data word 207B of one row of the Drows of the data RAM 122. That is, mux-reg 0A receives narrow data word0 of the data RAM 122 row, mux-reg 0B receives narrow data word 1 of thedata RAM 122 row, mux-reg 1A receives narrow data word 2 of the data RAM122 row, mux-reg 1B receives narrow data word 3 of the data RAM 122 row,and so forth to mux-reg 511A receives narrow data word 1022 of the dataRAM 122 row, and mux-reg 511B receives narrow data word 1023 of the dataRAM 122 row. Additionally, mux-reg 1A receives on its input 211A theoutput 209A of mux-reg 0A, mux-reg 1B receives on its input 211B theoutput 209B of mux-reg 0B, and so forth to mux-reg 511A that receives onits input 211A the output 209A of mux-reg 510A and mux-reg 511B thatreceives on its input 211B the output 209B of mux-reg 510B, and mux-reg0A receives on its input 211A the output 209A of mux-reg 511A andmux-reg 0B receives on its input 211B the output 209B of mux-reg 511B.Each of the mux-regs 208A/208B receives the control input 213 thatcontrols whether to select the data word 207A/207B or the rotated input211A/211B or the rotated input 1811A/1811B. Finally, mux-reg 1A receiveson its input 1811A the output 209B of mux-reg 0B, mux-reg 1B receives onits input 1811B the output 209A of mux-reg 1A, and so forth to mux-reg511A that receives on its input 1811A the output 209B of mux-reg 510Band mux-reg 511B that receives on its input 1811B the output 209A ofmux-reg 511A, and mux-reg 0A receives on its input 1811A the output 209Bof mux-reg 511B and mux-reg 0B receives on its input 1811B the output209A of mux-reg 0A. Each of the mux-regs 208A/208B receives the controlinput 213 that controls whether to select the data word 207A/207B or therotated input 211A/211B or the rotated input 1811A/1811B. As describedin more detail below, in one mode of operation, on a first clock cycle,the control input 213 controls each of the mux-regs 208A/208B to selectthe data word 207A/207B for storage in the register and for subsequentprovision to the ALU 204; and during subsequent clock cycles (e.g., M-1clock cycles as described above), the control input 213 controls each ofthe mux-regs 208A/208B to select the rotated input 1811A/1811B forstorage in the register and for subsequent provision to the ALU 204.

Referring now to FIG. 20, a table illustrating a program for storage inthe program memory 129 of and execution by the NNU 121 of FIG. 1 havingNPUs 126 according to the embodiment of FIG. 18 is shown. The exampleprogram of FIG. 20 is similar in many ways to the program of FIG. 4.However, differences will now be described. The initialize NPUinstruction at address 0 specifies that the NPU 126 is to be in a narrowconfiguration. Additionally, the multiply-accumulate rotate instructionat address 2 specifies a count of 1023 and requires 1023 clock cycles,as shown. This is because the example of FIG. 20 assumes effectively1024 narrow (e.g., 8-bit) neurons (NPUs) of a layer, each having 1024connection inputs from a previous layer of 1024 neurons, for a total of1024K connections. Each neuron receives an 8-bit data value from eachconnection input and multiplies the 8-bit data value by an appropriate8-bit weight value.

Referring now to FIG. 21, a timing diagram illustrating the execution ofthe program of FIG. 20 by the NNU 121 that includes NPUs 126 of FIG. 18operating in a narrow configuration is shown. The timing diagram of FIG.21 is similar in many ways to the timing diagram of FIG. 5; however,differences will now be described.

In the timing diagram of FIG. 21, the NPUs 126 are in a narrowconfiguration because the initialize NPU instruction at address 0initializes them to a narrow configuration. Consequently, the 512 NPUs126 effectively operate as 1024 narrow NPUs (or neurons), which aredesignated in the columns as NPU 0-A and NPU 0-B (the two narrow NPUs ofNPU 126 0), NPU 1-A and NPU 1-B (the two narrow NPUs of NPU 126 1) andso forth through NPU 511-A and NPU 511-B (the two narrow NPUs of NPU 126511). For simplicity and clarity of illustration, the operations onlyfor narrow NPUs 0-A, 0-B and 511-B are shown. Due to the fact that themultiply-accumulate rotate at address 2 specifies a count of 1023, whichrequires 1023 clocks, the rows of the timing diagram of FIG. 21 includeup to clock cycle 1026.

At clock 0, each of the 1024 NPUs performs the initializationinstruction of FIG. 4, which is illustrated in FIG. 5 by the assignmentof a zero value to the accumulator 202.

At clock 1, each of the 1024 narrow NPUs performs themultiply-accumulate instruction at address 1 of FIG. 20. Narrow NPU 0-Aaccumulates the accumulator 202A value (which is zero) with the productof data RAM 122 row 17 narrow word 0 and weight RAM 124 row 0 narrowword 0; narrow NPU 0-B accumulates the accumulator 202B value (which iszero) with the product of data RAM 122 row 17 narrow word 1 and weightRAM 124 row 0 narrow word 1; and so forth to narrow NPU 511-Baccumulates the accumulator 202B value (which is zero) with the productof data RAM 122 row 17 narrow word 1023 and weight RAM 124 row 0 narrowword 1023, as shown.

At clock 2, each of the 1024 narrow NPUs performs a first iteration ofthe multiply-accumulate rotate instruction at address 2 of FIG. 20.Narrow NPU 0-A accumulates the accumulator 202A value 217A with theproduct of the rotated narrow data word 1811A received from the mux-reg208B output 209B of narrow NPU 511-B (which was narrow data word 1023received from the data RAM 122) and weight RAM 124 row 1 narrow word 0;narrow NPU 0-B accumulates the accumulator 202B value 217B with theproduct of the rotated narrow data word 1811B received from the mux-reg208A output 209A of narrow NPU 0-A (which was narrow data word 0received from the data RAM 122) and weight RAM 124 row 1 narrow word 1;and so forth to narrow NPU 511-B accumulates the accumulator 202B value217B with the product of the rotated narrow data word 1811B receivedfrom the mux-reg 208A output 209A of narrow NPU 511-A (which was narrowdata word 1022 received from the data RAM 122) and weight RAM 124 row 1narrow word 1023, as shown.

At clock 3, each of the 1024 narrow NPUs performs a second iteration ofthe multiply-accumulate rotate instruction at address 2 of FIG. 20.Narrow NPU 0-A accumulates the accumulator 202A value 217A with theproduct of the rotated narrow data word 1811A received from the mux-reg208B output 209B of narrow NPU 511-B (which was narrow data word 1022received from the data RAM 122) and weight RAM 124 row 2 narrow word 0;narrow NPU 0-B accumulates the accumulator 202B value 217B with theproduct of the rotated narrow data word 1811B received from the mux-reg208A output 209A of narrow NPU 0-A (which was narrow data word 1023received from the data RAM 122) and weight RAM 124 row 2 narrow word 1;and so forth to narrow NPU 511-B accumulates the accumulator 202B value217B with the product of the rotated narrow data word 1811B receivedfrom the mux-reg 208A output 209A of narrow NPU 511-A (which was narrowdata word 1021 received from the data RAM 122) and weight RAM 124 row 2narrow word 1023, as shown. As indicated by the ellipsis of FIG. 21,this continues for each of the following 1021 clock cycles until . . . .

At clock 1024, each of the 1024 narrow NPUs performs a 1023^(rd)iteration of the multiply-accumulate rotate instruction at address 2 ofFIG. 20. Narrow NPU 0-A accumulates the accumulator 202A value 217A withthe product of the rotated narrow data word 1811A received from themux-reg 208B output 209B of narrow NPU 511-B (which was narrow data word1 received from the data RAM 122) and weight RAM 124 row 1023 narrowword 0; NPU 0-B accumulates the accumulator 202B value 217B with theproduct of the rotated narrow data word 1811B received from the mux-reg208A output 209A of NPU 0-A (which was narrow data word 2 received fromthe data RAM 122) and weight RAM 124 row 1023 narrow word 1; and soforth to NPU 511-B accumulates the accumulator 202B value with theproduct of the rotated narrow data word 1811B received from the mux-reg208A output 209A of NPU 511-A (which was narrow data word 0 receivedfrom the data RAM 122) and weight RAM 124 row 1023 narrow word 1023, asshown.

At clock 1025, the AFU 212A/212B of each of the 1024 narrow NPUsperforms the activation function instruction at address 3 of FIG. 20.Finally, at clock 1026, each of the 1024 narrow NPUs performs the writeAFU output instruction at address 4 of FIG. 20 by writing back itsnarrow result 133A/133B to its corresponding narrow word of row 16 ofthe data RAM 122, i.e., the narrow result 133A of NPU 0-A is written tonarrow word 0 of the data RAM 122, the narrow result 133B of NPU 0-B iswritten to narrow word 1 of the data RAM 122, and so forth to the narrowresult 133 of NPU 511-B is written to narrow word 1023 of the data RAM122. The operation described above with respect to FIG. 21 is also shownin block diagram form in FIG. 22.

Referring now to FIG. 22, a block diagram illustrating the NNU 121 ofFIG. 1 including the NPUs 126 of FIG. 18 to execute the program of FIG.20 is shown. The NNU 121 includes the 512 NPUs 126, i.e., 1024 narrowNPUs, the data RAM 122 that receives its address input 123, and theweight RAM 124 that receives its address input 125. Although not shown,on clock 0 the 1024 narrow NPUs perform the initialization instructionof FIG. 20. As shown, on clock 1, the 1024 8-bit data words of row 17are read out of the data RAM 122 and provided to the 1024 narrow NPUs.On clocks 1 through 1024, the 1024 8-bit weight words of rows 0 through1023, respectively, are read out of the weight RAM 124 and provided tothe 1024 narrow NPUs. Although not shown, on clock 1, the 1024 narrowNPUs perform their respective multiply-accumulate operations on theloaded data words and weight words. On clocks 2 through 1024, themux-regs 208A/208B of the 1024 narrow NPUs operate as a 1024 8-bit wordrotater to rotate the previously loaded data words of row 17 of the dataRAM 122 to the adjacent narrow NPU, and the narrow NPUs perform themultiply-accumulate operation on the respective rotated data narrow wordand the respective narrow weight word loaded from the weight RAM 124.Although not shown, on clock 1025, the 1024 narrow AFUs 212A/212Bperform the activation instruction. On clock 1026, the 1024 narrow NPUswrite back their respective 1024 8-bit results 133A/133B to row 16 ofthe data RAM 122.

As may be observed, the embodiment of FIG. 18 may be advantageous overthe embodiment of FIG. 2, for example, because it provides theflexibility for the programmer to perform computations using wide dataand weight words (e.g., 16-bits) when that amount of precision is neededby the particular application being modeled and narrow data and weightwords (e.g., 8-bits) when that amount of precision is needed by theapplication. From one perspective, the embodiment of FIG. 18 providesdouble the throughput over the embodiment of FIG. 2 for narrow dataapplications at the cost of the additional narrow elements (e.g.,mux-reg 208B, reg 205B, narrow ALU 204B, narrow accumulator 202B, narrowAFU 212B), which is approximately a 50% increase in area of the NPU 126.

Tri-Mode NPUs

Referring now to FIG. 23, a block diagram illustrating a dynamicallyconfigurable NPU 126 of FIG. 1 according to an alternate embodiment isshown. The NPU 126 of FIG. 23 is configurable not only in wide andnarrow configurations, but also in a third configuration referred toherein as a “funnel” configuration. The NPU 126 of FIG. 23 is similar inmany respects to the NPU 126 of FIG. 18. However, the wide adder 244A ofFIG. 18 is replaced in the NPU 126 of FIG. 23 with a 3-input wide adder2344A that receives a third addend 2399 that is an extended version ofthe output of the narrow mux 1896B. A program for operating an NNU 121having the NPUs 126 of FIG. 23 is similar in most respects to theprogram of FIG. 20. However, the initialize NPU instruction at address 0initializes the NPUs 126 to a funnel configuration, rather than a narrowconfiguration. Additionally, the count of the multiply-accumulate rotateinstruction at address 2 is 511 rather than 1023.

When in the funnel configuration, the NPU 126 operates similarly to whenin the narrow configuration when executing a multiply-accumulateinstruction such as at address 1 of FIG. 20 in that it receives twonarrow data words 207A/207B and two narrow weight words 206A/206B; thewide multiplier 242A multiplies data word 209A and weight word 203A togenerate product 246A which the wide mux 1896A selects; and the narrowmultiplier 242B multiplies data word 209B and weight word 203B togenerate product 246B which the narrow mux 1896B selects. However, thewide adder 2344A adds both the product 246A (selected by wide mux 1896A)and the product 246B/2399 (selected by wide mux 1896B) to the wideaccumulator 202A value 217A, and narrow adder 244B and narrowaccumulator 202B are inactive. Furthermore, when in the funnelconfiguration, when executing a multiply-accumulate rotate instructionsuch as at address 2 of FIG. 20, the control input 213 causes themux-regs 208A/208B to rotate by two narrow words (e.g., 16-bits), i.e.,the mux-regs 208A/208B select their respective 211A/211B inputs as ifthey were in a wide configuration. However, the wide multiplier 242Amultiplies data word 209A and weight word 203A to generate product 246Awhich the wide mux 1896A selects; and the narrow multiplier 242Bmultiplies data word 209B and weight word 203B to generate product 246Bwhich the narrow mux 1896B selects; and the wide adder 2344A adds boththe product 246A (selected by wide mux 1896A) and the product 246B/2399(selected by wide mux 1896B) to the wide accumulator 202A value 217A,and the narrow adder 244B and narrow accumulator 202B are inactive asdescribed above. Finally, when in the funnel configuration, whenexecuting an activation function instruction such as at address 3 ofFIG. 20, the wide AFU 212A performs the activation function on theresulting sum 215A to generate a narrow result 133A and the narrow AFU212B is inactive. Hence, only the A narrow NPUs generate a narrow result133A, and the narrow results 133B generated by the B narrow NPUs areinvalid. Consequently, the row of results written back (e.g., to row 16as at the instruction at address 4 of FIG. 20) includes holes since onlythe narrow results 133A are valid and the narrow results 133B areinvalid. Thus, conceptually, each clock cycle each neuron (NPU 126 ofFIG. 23) processes two connection data inputs, i.e., multiplies twonarrow data words by their respective weights and accumulates the twoproducts, in contrast to the embodiments of FIGS. 2 and 18 which eachprocess a single connection data input per clock cycle.

As may be observed with respect to the embodiment of FIG. 23, the numberof result words (neuron outputs) produced and written back to the dataRAM 122 or weight RAM 124 is half the square root of the number of datainputs (connections) received and the written back row of results hasholes, i.e., every other narrow word result is invalid, morespecifically, the B narrow NPU results are not meaningful. Thus, theembodiment of FIG. 23 may be particularly efficient in neural networkshaving two successive layers in which, for example, the first layer hastwice as many neurons as the second layer (e.g., the first layer has1024 neurons fully connected to a second layer of 512 neurons).Furthermore, the other execution units 112 (e.g., media units, such asx86 AVX units) may perform pack operations on a disperse row of results(i.e., having holes) to make compact it (i.e., without holes), ifnecessary, for use in subsequent computations while the NNU 121 isperforming other computations associated with other rows of the data RAM122 and/or weight RAM 124.

Hybrid NNU Operation; Convolution and Pooling Capabilities

An advantage of the NNU 121 according to embodiments described herein isthat the NNU 121 is capable of concurrently operating in a fashion thatresembles a coprocessor in that it executes its own internal program andoperating in a fashion that resembles an execution unit of a processorin that it executes architectural instructions (or microinstructionstranslated therefrom) issued to it. The architectural instructions areof an architectural program being performed by the processor thatincludes the NNU 121. In this manner, the NNU 121 operates in a hybridfashion, which is advantageous because it provides the ability tosustain high utilization of the NNU 121. For example, the FIGS. 24through 26 illustrate the operation of the NNU 121 to perform aconvolution operation in which the NNU 121 is highly utilized, and FIGS.27 through 28 illustrate the operation of the NNU 121 to perform apooling operation, which are required for convolution layers and poolinglayers and other digital data computing applications, such as imageprocessing (e.g., edge detection, sharpening, blurring,recognition/classification). However, the hybrid operation of the NNU121 is not limited to performing a convolution or pooling operation,rather the hybrid feature may be used to perform other operations, suchas classic neural network multiply-accumulate and activation functionoperations as described above with respect to FIGS. 4 through 13. Thatis, the processor 100 (more specifically, the reservation stations 108)issue MTNN 1400 and MFNN 1500 instructions to the NNU 121 in response towhich the NNU 121 writes data to the memories 122/124/129 and readsresults from the memories 122/124 written there by the NNU 121, whileconcurrently the NNU 121 reads and writes the memories 122/124/129 inresponse to executing programs written to the program memory 129 by theprocessor 100 (via MTNN 1400 instructions).

Referring now to FIG. 24, a block diagram illustrating an example ofdata structures used by the NNU 121 of FIG. 1 to perform a convolutionoperation are shown. The block diagram includes a convolution kernel2402, a data array 2404, and the data RAM 122 and weight RAM 124 ofFIG. 1. Preferably, the data array 2404 (e.g., of image pixels) is heldin system memory (not shown) attached to the processor 100 and loadedinto the weight RAM 124 of the NNU 121 by the processor 100 executingMTNN instructions 1400. A convolution operation is an operation thatconvolves a first matrix with a second matrix, the second matrixreferred to as a convolution kernel herein. As understood in the contextof the present disclosure, a convolution kernel is a matrix ofcoefficients, which may also be referred to as weights, parameters,elements or values. Preferably, the convolution kernel 2402 is staticdata of the architectural program being executed by the processor 100.

The data array 2404 is a two-dimensional array of data values, and eachdata value (e.g., an image pixel value) is the size of a word of thedata RAM 122 or weight RAM 124 (e.g., 16 bits or 8 bits). In theexample, the data values are 16-bit words and the NNU 121 is configuredas 512 wide configuration NPUs 126. Additionally, in the embodiment, theNPUs 126 include mux-regs for receiving the weight words 206 from theweight RAM 124, such as mux-reg 705 of FIG. 7, in order to perform thecollective rotater operation of a row of data values received from theweight RAM 124, as described in more detail below. In the example, thedata array 2404 is a 2560 column×1600 row pixel array. When thearchitectural program convolves the data array 2404 with the convolutionkernel 2402, it breaks the data array 2404 into 20 chunks, each chunkbeing a 512×400 data matrix 2406, as shown.

The convolution kernel 2402, in the example, is a 3×3 matrix ofcoefficients, or weights, or parameters, or elements. The first row ofcoefficients are denoted C0,0; C0,1; and C0,2; the second row ofcoefficients are denoted C1,0; C1,1; and C1,2; and the third row ofcoefficients are denoted C2,0; C2,1; and C2,2. For example, aconvolution kernel that may be used for performing edge detection hasthe following coefficients: 0, 1, 0, 1, −4, 1, 0, 1, 0. For anotherexample, a convolution kernel that may be used to Gaussian blur an imagehas the following coefficients: 1, 2, 1, 2, 4, 2, 1, 2, 1. In this case,a divide is typically performed on the final accumulated value, wherethe divisor is the sum of the absolute values of the elements of theconvolution kernel 2402, which is 16 in this example. For anotherexample, the divisor is the number of elements of the convolution kernel2402. For another example, the divisor is a value that compresses theconvolutions back within a desired range of values, and the divisor isdetermined from the values of the elements of the convolution kernel2402 and the desired range and the range of the input values of thematrix being convolved.

As shown in FIG. 24 and described in more detail with respect to FIG.25, the architectural program writes the data RAM 122 with thecoefficients of the convolution kernel 2402. Preferably, all the wordsof each of nine (the number of elements in the convolution kernel 2402)consecutive rows of the data RAM 122 are written with a differentelement of the convolution kernel 2402 in row-major order. That is, eachword of one row is written with the first coefficient C0,0; the next rowis written with the second coefficient C0,1; the next row is writtenwith the third coefficient C0,2; the next row is written with the fourthcoefficient C1,0; and so forth until each word of the ninth row iswritten with the ninth coefficient C2,2, as shown. To convolve a datamatrix 2406 of a chunk of the data array 2404, the NPUs 126 repeatedlyread, in order, the nine rows of the data RAM 122 that hold theconvolution kernel 2402 coefficients, as described in more detail below,particularly with respect to FIG. 26A.

As shown in FIG. 24 and described in more detail with respect to FIG.25, the architectural program writes the weight RAM 124 with the valuesof a data matrix 2406. As the NNU program performs the convolution, itwrites back the resulting matrix to the weight RAM 124. Preferably, thearchitectural program writes a first data matrix 2406 to the weight RAM124 and starts the NNU 121, and while the NNU 121 is convolving thefirst data matrix 2406 with the convolution kernel 2402, thearchitectural program writes a second data matrix 2406 to the weight RAM124 so that as soon as the NNU 121 completes the convolution of thefirst data matrix 2406, the NNU 121 can start convolving the second datamatrix 2406, as described in more detail with respect to FIG. 25. Inthis manner, the architectural program ping-pongs back and forth betweenthe two regions of the weight RAM 124 in order to keep the NNU 121 fullyutilized. Thus, the example of FIG. 24 shows a first data matrix 2406Acorresponding to a first chunk occupying rows 0 through 399 of theweight RAM 124, and a second data matrix 2406B corresponding to a secondchunk occupying rows 500 through 899 of the weight RAM 124. Furthermore,as shown, the NNU 121 writes back the results of the convolutions torows 900-1299 and 1300-1699 of the weight RAM 124, which thearchitectural program subsequently reads out of the weight RAM 124. Thedata values of the data matrix 2406 held in the weight RAM 124 aredenoted “Dx,y” where “x” is the weight RAM 124 row number and “y” is theword, or column, number of the weight RAM 124. Thus, for example, dataword 511 in row 399 is denoted D399, 511 in FIG. 24, which is receivedby the mux-reg 705 of NPU 511.

Referring now to FIG. 25, a flowchart illustrating operation of theprocessor 100 of FIG. 1 to perform an architectural program that usesthe NNU 121 to perform a convolution of the convolution kernel 2402 withthe data array 2404 of FIG. 24. Flow begins at block 2502.

At block 2502, the processor 100, i.e., the architectural programrunning on the processor 100, writes the convolution kernel 2402 of FIG.24 to the data RAM 122 in the manner shown and described with respect toFIG. 24. Additionally, the architectural program initializes a variableN to a value of 1. The variable N denotes the current chunk of the dataarray 2404 being processed by the NNU 121. Additionally, thearchitectural program initializes a variable NUM_CHUNKS to a value of20. Flow proceeds to block 2504.

At block 2504, the processor 100 writes the data matrix 2406 for chunk 1to the weight RAM 124, as shown in FIG. 24 (e.g., data matrix 2406A ofchunk 1). Flow proceeds to block 2506.

At block 2506, the processor 100 writes a convolution program to the NNU121 program memory 129, using MTNN 1400 instructions that specify afunction 1432 to write the program memory 129. The processor 100 thenstarts the NNU convolution program using a MTNN 1400 instruction thatspecifies a function 1432 to start execution of the program. An exampleof the NNU convolution program is described in more detail with respectto FIG. 26A. Flow proceeds to decision block 2508.

At decision block 2508, the architectural program determines whether thevalue of variable N is less than NUM_CHUNKS. If so, flow proceeds toblock 2512; otherwise, flow proceeds to block 2514.

At block 2512, the processor 100 writes the data matrix 2406 for chunkN+1 to the weight RAM 124, as shown in FIG. 24 (e.g., data matrix 2406Bof chunk 2). Thus, advantageously, the architectural program writes thedata matrix 2406 for the next chunk to the weight RAM 124 while the NNU121 is performing the convolution on the current chunk so that the NNU121 can immediately start performing the convolution on the next chunkonce the convolution of the current chunk is complete, i.e., written tothe weight RAM 124. Flow proceeds to block 2514.

At block 2514, the processor 100 determines that the currently runningNNU program (started at block 2506 in the case of chunk 1, and startedat block 2518 in the case of chunks 2-20) has completed. Preferably, theprocessor 100 determines this by executing a MFNN 1500 instruction toread the NNU 121 status register 127. In an alternate embodiment, theNNU 121 generates an interrupt to indicate it has completed theconvolution program. Flow proceeds to decision block 2516.

At decision block 2516, the architectural program determines whether thevalue of variable N is less than NUM_CHUNKS. If so, flow proceeds toblock 2518; otherwise, flow proceeds to block 2522.

At block 2518, the processor 100 updates the convolution program so thatit can convolve chunk N+1. More specifically, the processor 100 updatesthe weight RAM 124 row value of the initialize NPU instruction ataddress 0 to the first row of the data matrix 2406 (e.g., to row 0 fordata matrix 2406A or to row 500 for data matrix 2406B) and updates theoutput row (e.g., to 900 or 1300). The processor 100 then starts theupdated NNU convolution program. Flow proceeds to block 2522.

At block 2522, the processor 100 reads the results of the NNUconvolution program from the weight RAM 124 for chunk N. Flow proceedsto decision block 2524.

At decision block 2524, the architectural program determines whether thevalue of variable N is less than NUM_CHUNKS. If so, flow proceeds toblock 2526; otherwise, flow ends.

At block 2526, the architectural program increments N by one. Flowreturns to decision block 2508.

Referring now to FIG. 26A, a program listing of an NNU program thatperforms a convolution of a data matrix 2406 with the convolution kernel2402 of FIG. 24 and writes it back to the weight RAM 124 is shown. Theprogram loops a number of times through a loop body of instructions ataddresses 1 through 9. An initialize NPU instruction at address 0specifies the number of times each NPU 126 executes the loop body, whichin the example of FIG. 26A has a loop count value of 400, correspondingto the number of rows in a data matrix 2406 of FIG. 24, and a loopinstruction at the end of the loop (at address 10) decrements thecurrent loop count value and if the result is non-zero causes control toreturn to the top of the loop body (i.e., to the instruction at address1). The initialize NPU instruction also clears the accumulator 202 tozero. Preferably, the loop instruction at address 10 also clears theaccumulator 202 to zero. Alternatively, as described above, themultiply-accumulate instruction at address 1 may specify to clear theaccumulator 202 to zero.

For each execution of the loop body of the program, the 512 NPUs 126concurrently perform 512 convolutions of the 3×3 convolution kernel 2402and 512 respective 3×3 sub-matrices of a data matrix 2406. Theconvolution is the sum of the nine products of an element of theconvolution kernel 2402 and its corresponding element of the respectivesub-matrix. In the embodiment of FIG. 26A, the origin (center element)of each of the 512 respective 3×3 sub-matrices is the data word Dx+1,y+1of FIG. 24, where y (column number) is the NPU 126 number, and x (rownumber) is the current weight RAM 124 row number that is read by themultiply-accumulate instruction at address 1 of the program of FIG. 26A(also, the row number is initialized by the initialize NPU instructionat address 0, incremented at each of the multiply-accumulateinstructions at addresses 3 and 5, and updated by the decrementinstruction at address 9). Thus, for each loop of the program, the 512NPUs 126 compute the 512 convolutions and write the 512 convolutionresults back to a specified row of the weight RAM 124. In the presentdescription, edge handling is ignored for simplicity, although it shouldbe noted that the use of the collective rotating feature of the NPUs 126will cause wrapping for two of the columns from one vertical edge of thedata matrix 2406 (e.g., of the image in the case of image processing) tothe other vertical edge (e.g., from the left edge to the right edge orvice versa). The loop body will now be described.

At address 1 is a multiply-accumulate instruction that specifies row 0of the data RAM 122 and implicitly uses the current weight RAM 124 row,which is preferably held in the sequencer 128 (and which is initializedto zero by the instruction at address 0 for the first pass through theloop body). That is, the instruction at address 1 causes each of theNPUs 126 to read its corresponding word from row 0 of the data RAM 122and read its corresponding word from the current weight RAM 124 row andperform a multiply-accumulate operation on the two words. Thus, forexample, NPU 5 multiplies C0,0 and Dx,5 (where “x” is the current weightRAM 124 row), adds the result to the accumulator 202 value 217 andwrites the sum back to the accumulator 202.

At address 2 is a multiply-accumulate instruction that specifies toincrement the data RAM 122 row (i.e., to row 1) and then read the rowfrom the data RAM 122 at the incremented address. The instruction alsospecifies to rotate the values in the mux-reg 705 of each NPU 126 to theadjacent NPU 126, which in this case is the row of data matrix 2406values just read from the weight RAM 124 in response to the instructionat address 1. In the embodiment of FIGS. 24 through 26, the NPUs 126 areconfigured to rotate the values of the mux-regs 705 to the left, i.e.,from NPU J to NPU J−1, rather than from NPU J to NPU J+1 as describedabove with respect to FIGS. 3, 7 and 19. It should be understood that inan embodiment in which the NPUs 126 are configured to rotate right, thearchitectural program may write the convolution kernel 2402 coefficientvalues to the data RAM 122 in a different order (e.g., rotated aroundits central column) in order to accomplish a similar convolution result.Furthermore, the architectural program may perform additionalpre-processing (e.g., transposition) of the convolution kernel 2402 asneeded. Additionally, the instruction specifies a count value of 2.Thus, the instruction at address 2 causes each of the NPUs 126 to readits corresponding word from row 1 of the data RAM 122 and receive therotated word into the mux-reg 705 and perform a multiply-accumulateoperation on the two words. Due to the count value of 2, the instructionalso causes each of the NPUs 126 to repeat the operation just described.That is, the sequencer 128 increments the data RAM 122 row address 123(i.e., to row 2) and each NPU 126 reads its corresponding word from row2 of the data RAM 122 and receives the rotated word into the mux-reg 705and performs a multiply-accumulate operation on the two words. Thus, forexample, assuming the current weight RAM 124 row is 27, after executingthe instruction at address 2, NPU 5 will have accumulated into itsaccumulator 202 the product of C0,1 and D27,6 and the product of C0,2and D27,7. Thus, after the completion of the instructions at addresses 1and 2, the product of C0,0 and D27,5, the product of C0,1 and D27,6, andthe product of C0,2 and D27,7 will have been accumulated into theaccumulator 202, along with all the other accumulated values fromprevious passes through the loop body.

The instructions at addresses 3 and 4 perform a similar operation as theinstructions at addresses 1 and 2, however for the next row of theweight RAM 124, by virtue of the weight RAM 124 row increment indicator,and for the next three rows of the data RAM 122, i.e., rows 3 through 5.That is, with respect to NPU 5, for example, after the completion of theinstructions at addresses 1 through 4, the product of C0,0 and D27,5,the product of C0,1 and D27,6, the product of C0,2 and D27,7, theproduct of C1,0 and D28,5, the product of C1,1 and D28,6, and theproduct of C1,2 and D28,7 will have been accumulated into theaccumulator 202, along with all the other accumulated values fromprevious passes through the loop body.

The instructions at addresses 5 and 6 perform a similar operation as theinstructions at addresses 3 and 4, however for the next row of theweight RAM 124, and for the next three rows of the data RAM 122, i.e.,rows 6 through 8. That is, with respect to NPU 5, for example, after thecompletion of the instructions at addresses 1 through 6, the product ofC0,0 and D27,5, the product of C0,1 and D27,6, the product of C0,2 andD27,7, the product of C1,0 and D28,5, the product of C1,1 and D28,6, theproduct of C1,2 and D28,7, the product of C2,0 and D29,5, the product ofC2,1 and D29,6, and the product of C2,2 and D29,7 will have beenaccumulated into the accumulator 202, along with all the otheraccumulated values from previous passes through the loop body. That is,after the completion of the instructions at addresses 1 through 6, andassuming the weight RAM 124 row at the beginning of the loop body was27, NPU 5, for example, will have used the convolution kernel 2402 toconvolve the following 3×3 sub-matrix:

D27,5 D27,6 D27,7 D28,5 D28,6 D28,7 D29,5 D29,6 D29,7More generally, after the completion of the instructions at addresses 1through 6, each of the 512 NPUs 126 will have used the convolutionkernel 2402 to convolve the following 3×3 sub-matrix:

Dr, n Dr, n + 1 Dr, n + 2 Dr + 1, n Dr + 1, n + 1 Dr + 1, n + 2 Dr + 2,n Dr + 2, n + 1 Dr + 2, n + 2where r is the weight RAM 124 row address value at the beginning of theloop body, and n is the NPU 126 number.

The instruction at address 7 passes through the accumulator 202 value217 through the AFU 212. The pass through function passes through a wordthat is the size (in bits) of the words read from the data RAM 122 andweight RAM 124 (i.e., in the example, 16 bits). Preferably, the user mayspecify the format of the output, e.g., how many of the output bits arefractional bits, as described in more detail below. Alternatively,rather than specifying a pass through activation function, a divideactivation function is specified that divides the accumulator 202 value217 by a divisor, such as described herein, e.g., with respect to FIGS.29A and 30, e.g., using one of the “dividers” 3014/3016 of FIG. 30. Forexample, in the case of a convolution kernel 2402 with a coefficient,such as the one-sixteenth coefficient of the Gaussian blur kerneldescribed above, rather than a pass through function, the activationfunction instruction at address 7 may specify a divide (e.g., by 16)activation function. Alternatively, the architectural program mayperform the divide by 16 on the convolution kernel 2402 coefficientsbefore writing them to the data RAM 122 and adjust the location of thebinary point accordingly for the convolution kernel 2402 values, e.g.,using the data binary point 2922 of FIG. 29, described below.

The instruction at address 8 writes the output of the AFU 212 to the rowof the weight RAM 124 specified by the current value of the output rowregister, which was initialized by the instruction at address 0 andwhich is incremented each pass through the loop by virtue of theincrement indicator in the instruction.

As may be determined from the example of FIGS. 24 through 26 having a3×3 convolution kernel 2402, the NPUs 126 read the weight RAM 124approximately every third clock cycle to read a row of the data matrix2406 and write the weight RAM 124 approximately every 12 clock cycles towrite the convolution result matrix. Additionally, assuming anembodiment that includes a write and read buffer such as the buffer 1704of FIG. 17, concurrently with the NPU 126 reads and writes, theprocessor 100 reads and writes the weight RAM 124 such that the buffer1704 performs one write and one read of the weight RAM 124 approximatelyevery 16 clock cycles to write the data matrices 2406 and to read theconvolution result matrices, respectively. Thus, approximately half thebandwidth of the weight RAM 124 is consumed by the hybrid manner inwhich the NNU 121 performs the convolution operation. Although theexample includes a 3×3 convolution kernel 2402, other size convolutionkernels may be employed, such as 2×2, 4×4, 5×5, 6×6, 7×7, 8×8, etc.matrices, in which case the NNU program will vary. In the case of alarger convolution kernel, a smaller percentage of the weight RAM 124bandwidth is consumed since the NPUs 126 read the weight RAM 124 asmaller percentage of the time because the count in the rotatingversions of the multiply-accumulate instructions is larger (e.g., ataddresses 2, 4 and 6 of the program of FIG. 26A and additional suchinstructions that would be needed for a larger convolution kernel).

Alternatively, rather than writing back the results of the convolutionsto different rows of the weight RAM 124 (e.g., 900-1299 and 1300-1699),the architectural program configures the NNU program to overwrite rowsof the input data matrix 2406 after the rows are no longer needed. Forexample, in the case of a 3×3 convolution kernel, rather than writingthe data matrix 2406 into rows 0-399 of the weight RAM 124, thearchitectural program writes the data matrix 2406 into rows 2-401, andthe NNU program is configured to write the convolution results to theweight RAM 124 beginning at row 0 and incrementing each pass through theloop body. In this fashion, the NNU program is overwriting only rowsthat are no longer needed. For example, after the first pass through theloop body (or more specifically after the execution of the instructionat address 1 which loads in row 0 of the weight RAM 124), the data inrow 0 can now be overwritten, although the data in rows 1-3 will beneeded in the second pass through the loop body and are therefore notoverwritten by the first pass through the loop body; similarly, afterthe second pass through the loop body, the data in row 1 can now beoverwritten, although the data in rows 2-4 will be needed in the secondpass through the loop body and are therefore not overwritten by thesecond pass through the loop body; and so forth. In such an embodiment,the height of each data matrix 2406 (chunk) may be larger (e.g., 800rows), resulting in fewer chunks.

Alternatively, rather than writing back the results of the convolutionsto the weight RAM 124, the architectural program configures the NNUprogram to write back the results of the convolutions to rows of thedata RAM 122 above the convolution kernel 2402 (e.g., above row 8), andthe architectural program reads the results from the data RAM 122 as theNNU 121 writes them (e.g., using the address of the most recentlywritten data RAM 122 row 2606 of FIG. 26B, described below). Thisalternative may be advantageous in an embodiment in which the weight RAM124 is single-ported and the data RAM 122 is dual-ported.

As may be observed from the operation of the NNU 121 according to theembodiment of FIGS. 24 through 26A, each execution of the program ofFIG. 26A takes approximately 5000 clock cycles and, consequently, theconvolving of the entire 2560×1600 data array 2404 of FIG. 24 takesapproximately 100,000 clock cycles, which may be considerably less thanthe number of clock cycles required to perform a similar task byconventional methods.

Referring now to FIG. 26B, a block diagram illustrating certain fieldsof the control register 127 of the NNU 121 of FIG. 1 according to oneembodiment is shown. The status register 127 includes a field 2602 thatindicates the address of the most recent row of the weight RAM 124written by the NPUs 126; a field 2606 that indicates the address of themost recent row of the data RAM 122 written by the NPUs 126; a field2604 that indicates the addresses of the most recent row of the weightRAM 124 read by the NPUs 126; and a field 2608 that indicates theaddresses of the most recent row of the data RAM 122 read by the NPUs126. This enables the architectural program executing on the processor100 to determine the progress of the NNU 121 as it marches throughreading and/or writing the data RAM 122 and/or weight RAM 124. Employingthis capability, along with the choice to overwrite the input datamatrix as described above (or to write the results to the data RAM 122,as mentioned above), the data array 2404 of FIG. 24 may be processed as5 chunks of 512×1600 rather than 20 chunks of 512×400, for example, asfollows. The processor 100 writes a first 512×1600 chunk into the weightRAM 124 starting at row 2 and starts the NNU program (which has a loopcount of 1600 and an initialized weight RAM 124 output row of 0). As theNNU 121 executes the NNU program, the processor 100 monitors thelocation/address of the weight RAM 124 output in order to (1) read(using MFNN 1500 instructions) the rows of the weight RAM 124 that havevalid convolution results written by the NNU 121 (beginning at row 0),and (2) to write the second 512×1600 data matrix 2406 (beginning at row2) over the valid convolution results once they have already been read,so that when the NNU 121 completes the NNU program on the first 512×1600chunk, the processor 100 can immediately update the NNU program asneeded and start it again to process the second 512×1600 chunk. Thisprocess is repeated three more times for the remaining three 512×1600chunks to accomplish high utilization of the NNU 121.

Advantageously, in one embodiment, the AFU 212 includes the ability toefficiently perform an effective division of the accumulator 202 value217, as described in more detail below, particularly with respect toFIGS. 29A and 29B and 30. For example, an activation function NNUinstruction that divides the accumulator 202 value 217 by 16 may be usedfor the Gaussian blurring matrix described above.

Although the convolution kernel 2402 used in the example of FIG. 24 is asmall static convolution kernel applied to the entire data array 2404,in other embodiments the convolution kernel may be a large matrix thathas unique weights associated with the different data values of the dataarray 2404, such as is commonly found in convolutional neural networks.When the NNU 121 is used in such a manner, the architectural program mayswap the locations of the data matrix and the convolution kernel, i.e.,place the data matrix in the data RAM 122 and the convolution kernel inthe weight RAM 124, and the number of rows that may be processed by agiven execution of the NNU program may be relatively smaller.

Referring now to FIG. 27, a block diagram illustrating an example of theweight RAM 124 of FIG. 1 populated with input data upon which a poolingoperation is performed by the NNU 121 of FIG. 1. A pooling operation,performed by a pooling layer of an artificial neural network, reducesthe dimensions of a matrix of input data (e.g., an image or convolvedimage) by taking sub-regions, or sub-matrices, of the input matrix andcomputing either the maximum or average value of the sub-matrices, andthe maximum or average values become a resulting matrix, or pooledmatrix. In the example of FIGS. 27 and 28, the pooling operationcomputes the maximum value of each sub-matrix. Pooling operations areparticularly useful in artificial neural networks that perform objectclassification or detection, for example. Generally, a pooling operationeffectively reduces the size of its input matrix by a factor of thenumber of elements in the sub-matrix examined, and in particular,reduces the input matrix in each dimension by the number of elements inthe corresponding dimension of the sub-matrix. In the example of FIG.27, the input data is a 512×1600 matrix of wide words (e.g., 16 bits)stored in rows 0 through 1599 of the weight RAM 124. In FIG. 27, thewords are denoted by their row, column location, e.g., the word in row 0and column 0 is denoted D0,0; the word in row 0 and column 1 is denotedD0,1; the word in row 0 and column 2 is denoted D0,2; and so forth tothe word in row 0 and column 511 is denoted D0,511. Similarly, the wordin row 1 and column 0 is denoted D1,0; the word in row 1 and column 1 isdenoted D1,1; the word in row 1 and column 2 is denoted D1,2; and soforth to the word in row 1 and column 511 is denoted D1,511; and soforth to the word in row 1599 and column 0 is denoted D1599,0; the wordin row 1599 and column 1 is denoted D1599,1; the word in row 1599 andcolumn 2 is denoted D1599,2; and so forth to the word in row 1599 andcolumn 511 is denoted D1599,511.

Referring now to FIG. 28, a program listing of an NNU program thatperforms a pooling operation of the input data matrix of FIG. 27 andwrites it back to the weight RAM 124 is shown. In the example of FIG.28, the pooling operation computes the maximum value of respective 4×4sub-matrices of the input data matrix. The program loops a number oftimes through a loop body of instructions at addresses 1 through 10. Aninitialize NPU instruction at address 0 specifies the number of timeseach NPU 126 executes the loop body, which in the example of FIG. 28 hasa loop count value of 400, and a loop instruction at the end of the loop(at address 11) decrements the current loop count value and if theresult is non-zero causes control to return to the top of the loop body(i.e., to the instruction at address 1). The input data matrix in theweight RAM 124 is effectively treated by the NNU program as 400 mutuallyexclusive groups of four adjacent rows, namely rows 0-3, rows 4-7, rows8-11 and so forth to rows 1596-1599. Each group of four adjacent rowsincludes 128 4×4 sub-matrices, namely the 4×4 sub-matrices of elementsformed by the intersection of the four rows of a group and four adjacentcolumns, namely columns 0-3, 4-7, 8-11 and so forth to columns 508-511.Of the 512 NPUs 126, every fourth NPU 126 of the 512 NPUs 126 (i.e.,128) performs a pooling operation on a respective 4×4 sub-matrix, andthe other three-fourths of the NPUs 126 are unused. More specifically,NPUs 0, 4, 8, and so forth to NPU 508 each perform a pooling operationon their respective 4×4 sub-matrix whose left-most column numbercorresponds to the NPU number and whose lower row corresponds to thecurrent weight RAM 124 row value, which is initialized to zero by theinitialize instruction at address 0 and is incremented by four upon eachiteration of the loop body, as described in more detail below. The 400iterations of the loop body correspond to the number of groups of 4×4sub-matrices of the input data matrix of FIG. 27 (the 1600 rows of theinput data matrix divided by 4). The initialize NPU instruction alsoclears the accumulator 202 to zero. Preferably, the loop instruction ataddress 11 also clears the accumulator 202 to zero. Alternatively, themaxwacc instruction at address 1 specifies to clear the accumulator 202to zero.

For each iteration of the loop body of the program, the 128 used NPUs126 concurrently perform 128 pooling operations of the 128 respective4×4 sub-matrices of the current 4-row group of the input data matrix.More specifically, the pooling operation determines the maximum-valuedelement of the sixteen elements of the 4×4 sub-matrix. In the embodimentof FIG. 28, for each NPU y of the used 128 NPUs 126, the lower leftelement of the 4×4 sub-matrix is element Dx,y of FIG. 27, where x is thecurrent weight RAM 124 row number at the beginning of the loop body,which is read by the maxwacc instruction at address 1 of the program ofFIG. 28 (also, the row number is initialized by the initialize NPUinstruction at address 0, and incremented at each of the maxwaccinstructions at addresses 3, 5 and 7). Thus, for each loop of theprogram, the used 128 NPUs 126 write back to a specified row of theweight RAM 124 the corresponding maximum-valued element of therespective 128 4×4 sub-matrices of the current group of rows. The loopbody will now be described.

At address 1 is a maxwacc instruction that implicitly uses the currentweight RAM 124 row, which is preferably held in the sequencer 128 (andwhich is initialized to zero by the instruction at address 0 for thefirst pass through the loop body). The instruction at address 1 causeseach of the NPUs 126 to read its corresponding word from the current rowof the weight RAM 124, compare the word to the accumulator 202 value217, and store in the accumulator 202 the maximum of the two values.Thus, for example, NPU 8 determines the maximum value of the accumulator202 value 217 and data word Dx,8 (where “x” is the current weight RAM124 row) and writes the maximum value back to the accumulator 202.

At address 2 is a maxwacc instruction that specifies to rotate thevalues in the mux-reg 705 of each NPU 126 to the adjacent NPU 126, whichin this case is the row of input data matrix values just read from theweight RAM 124 in response to the instruction at address 1. In theembodiment of FIGS. 27 through 28, the NPUs 126 are configured to rotatethe values of the mux-regs 705 to the left, i.e., from NPU J to NPU J−1,as described above with respect to FIGS. 24 through 26. Additionally,the instruction specifies a count value of 3. Thus, the instruction ataddress 2 causes each of the NPUs 126 to receive the rotated word intothe mux-reg 705 and determine the maximum value of the rotated word andthe accumulator 202 value 217, and then to repeat this operation twomore times. That is, each NPU 126 receives the rotated word into themux-reg 705 and determines the maximum value of the rotated word and theaccumulator 202 value 217 three times. Thus, for example, assuming thecurrent weight RAM 124 row at the beginning of the loop body is 36,after executing the instruction at addresses 1 and 2, NPU 8, forexample, will have stored in its accumulator 202 the maximum value ofthe accumulator 202 at the beginning of the loop body and the fourweight RAM 124 words D36, 8 and D36,9 and D36,10 and D36,11.

The maxwacc instructions at addresses 3 and 4 perform a similaroperation as the instructions at addresses 1 and 2, however for the nextrow of the weight RAM 124, by virtue of the weight RAM 124 row incrementindicator. That is, assuming the current weight RAM 124 row at thebeginning of the loop body is 36, after the completion of theinstructions at addresses 1 through 4, NPU 8, for example, will havestored in its accumulator 202 the maximum value of the accumulator 202at the beginning of the loop body and the eight weight RAM 124 wordsD36,8 and D36,9 and D36,10 and D36,11 and D37,8 and D37,9 and D37,10 andD37,11.

The maxwacc instructions at addresses 5 through 8 perform a similaroperation as the instructions at addresses 3 and 4, however for the nexttwo rows of the weight RAM 124. That is, assuming the current weight RAM124 row at the beginning of the loop body is 36, after the completion ofthe instructions at addresses 1 through 8, NPU 8, for example, will havestored in its accumulator 202 the maximum value of the accumulator 202at the beginning of the loop body and the sixteen weight RAM 124 wordsD36,8 and D36,9 and D36,10 and D36,11 and D37,8 and D37,9 and D37,10 andD37,11 and D38,8 and D38,9 and D38,10 and D38,11 and D39,8 and D39,9 andD39,10 and D39,11. That is, after the completion of the instructions ataddresses 1 through 8, and assuming the weight RAM 124 row at thebeginning of the loop body was 36, NPU 8, for example, will havedetermined the maximum value of the following 4×4 sub-matrix:

D36,8 D36,9 D36,10 D36,11 D37,8 D37,9 D37,10 D37,11 D38,8 D38,9 D38,10D38,11 D39,8 D39,9 D39,10 D39,11More generally, after the completion of the instructions at addresses 1through 8, each of the used 128 NPUs 126 will have determined themaximum value of the following 4×4 sub-matrix:

Dr, n Dr, n + 1 Dr, n + 2 Dr, n + 3 Dr + 1, n Dr + 1, n + 1 Dr + 1, n +2 Dr + 1, n + 3 Dr + 2, n Dr + 2, n + 1 Dr + 2, n + 2 Dr + 2, n + 3 Dr +3, n Dr + 3, n + 1 Dr + 3, n + 2 Dr + 3, n + 3where r is the weight RAM 124 row address value at the beginning of theloop body, and n is the NPU 126 number.

The instruction at address 9 passes through the accumulator 202 value217 through the AFU 212. The pass through function passes through a wordthat is the size (in bits) of the words read from the weight RAM 124(i.e., in the example, 16 bits). Preferably, the user may specify theformat of the output, e.g., how many of the output bits are fractionalbits, as described in more detail below.

The instruction at address 10 writes the accumulator 202 value 217 tothe row of the weight RAM 124 specified by the current value of theoutput row register, which was initialized by the instruction at address0 and which is incremented each pass through the loop by virtue of theincrement indicator in the instruction. More specifically, theinstruction at address 10 writes a wide word (e.g., 16 bits) of theaccumulator 202 to the weight RAM 124. Preferably, the instructionwrites the 16 bits as specified by the output binary point 2916, asdescribe in more detail below with respect to FIGS. 29A and 29B below.

As may be observed, each row written to the weight RAM 124 by aniteration of the loop body includes holes that have invalid data. Thatis, the resulting 133 wide words 1 through 3, 5 through 7, 9 through 11and so forth to wide words 509 through 511 are invalid, or unused. Inone embodiment, the AFU 212 includes a mux that enables packing of theresults into adjacent words of a row buffer, such as the row buffer 1104of FIG. 11, for writing back to the output weight RAM 124 row.Preferably, the activation function instruction specifies the number ofwords in each hole, and the number of words in the hole is used tocontrol the mux to pack the results. In one embodiment, the number ofholes may be specified as values from 2 to 6 in order to pack the outputof pooling 3×3, 4×4, 5×5, 6×6 or 7×7 sub-matrices. Alternatively, thearchitectural program executing on the processor 100 reads the resultingsparse (i.e., including holes) result rows from the weight RAM 124 andperforms the packing function using other execution units 112, such as amedia unit using architectural pack instructions, e.g., x86 SSEinstructions. Advantageously, in a concurrent manner similar to thosedescribed above and exploiting the hybrid nature of the NNU 121, thearchitectural program executing on the processor 100 may read the statusregister 127 to monitor the most recently written row of the weight RAM124 (e.g., field 2602 of FIG. 26B) to read a resulting sparse row, packit, and write it back to the same row of the weight RAM 124 so that itis ready to be used as an input data matrix for a next layer of theneural network, such as a convolution layer or a classic neural networklayer (i.e., multiply-accumulate layer). Furthermore, although anembodiment is described that performs pooling operations on 4×4sub-matrices, the NNU program of FIG. 28 may be modified to performpooling operations on other size sub-matrices such as 3×3, 5×5, 6×6 or7×7 sub-matrices.

As may also be observed, the number of result rows written to the weightRAM 124 is one-fourth the number of rows of the input data matrix.Finally, in the example, the data RAM 122 is not used. However,alternatively, the data RAM 122 may be used rather than the weight RAM124 to perform a pooling operation.

In the example of FIGS. 27 and 28, the pooling operation computes themaximum value of the sub-region. However, the program of FIG. 28 may bemodified to compute the average value of the sub-region by, for example,replacing the maxwacc instructions with sumwacc instructions (sum theweight word with the accumulator 202 value 217) and changing theactivation function instruction at address 9 to divide (preferably viareciprocal multiply, as described below) the accumulated results by thenumber of elements of each sub-region, which is sixteen in the example.

As may be observed from the operation of the NNU 121 according to theembodiment of FIGS. 27 and 28, each execution of the program of FIG. 28takes approximately 6000 clock cycles to perform a pooling operation ofthe entire 512×1600 data matrix of FIG. 27, which may be considerablyless than the number of clock cycles required to perform a similar taskby conventional methods.

Alternatively, rather than writing back the results of the poolingoperation to the weight RAM 124, the architectural program configuresthe NNU program to write back the results to rows of the data RAM 122,and the architectural program reads the results from the data RAM 122 asthe NNU 121 writes them (e.g., using the address of the most recentlywritten data RAM 122 row 2606 of FIG. 26B). This alternative may beadvantageous in an embodiment in which the weight RAM 124 issingle-ported and the data RAM 122 is dual-ported.

Fixed-Point Arithmetic with User-Supplied Binary Points, Full PrecisionFixed-Point Accumulation, User-Specified Reciprocal Value, StochasticRounding of Accumulator Value, and Selectable Activation/OutputFunctions

Generally speaking, hardware units that perform arithmetic in digitalcomputing devices may be divided into what are commonly termed “integer”units and “floating-point” units, because they perform arithmeticoperations on integer and floating-point numbers, respectively. Afloating-point number has a magnitude (or mantissa) and an exponent, andtypically a sign. The exponent is an indication of the location of theradix point (typically binary point) with respect to the magnitude. Incontrast, an integer number has no exponent, but only a magnitude, andfrequently a sign. An advantage of a floating-point unit is that itenables a programmer to work with numbers that can take on differentvalues within on an enormously large range, and the hardware takes careof adjusting the exponent values of the numbers as needed without theprogrammer having to do so. For example, assume the two floating-pointnumbers 0.111×10²⁹ and 0.81×10³¹ are multiplied. (A decimal, or base 10,example is used here, although floating-point units most commonly workwith base 2 floating-point numbers.) The floating-point unitautomatically takes care of multiplying the mantissa, adding theexponents, and then normalizing the result back to a value of0.8991×10⁵⁹. For another example, assume the same two floating-pointnumbers are added. The floating-point unit automatically takes care ofaligning the binary points of the mantissas before adding them togenerate a resulting sum with a value of 0.81111×10³¹.

However, the complexity and consequent increase in size, powerconsumption and clocks per instruction and/or lengthened cycle timesassociated with floating-point units is well known. Indeed, for thisreason many devices (e.g., embedded processors, microcontrollers andrelatively low cost and/or low power microprocessors) do not include afloating-point unit. As may be observed from the example above, some ofthe complexities of floating-point units include logic that performsexponent calculations associated with floating-point addition andmultiplication/division (adders to add/subtract exponents of operands toproduce resulting exponent value for floating-pointmultiplication/division, subtracters to determine subtract exponents ofoperands to determine binary point alignment shift amounts forfloating-point addition), shifters that accomplish binary pointalignment of the mantissas for floating-point addition, shifters thatnormalize floating-point results. Additionally, flow proceeds to blockunits typically require logic to perform rounding of floating-pointresults, logic to convert between integer and floating-point formats orbetween different floating-point precision formats (e.g., extendedprecision, double precision, single precision, half precision), leadingzero and leading one detectors, and logic to deal with specialfloating-point numbers, such as denormal numbers, NANs and infinity.

Furthermore, there is the disadvantage of the significant complexity inverification of the correctness of a floating-point unit largely due tothe increased number space over which the design must be verified, whichmay lengthen the product development cycle and time to market. Stillfurther, as described above, floating-point arithmetic implies thestorage and use of separate mantissa and exponent fields for eachfloating-point number involved in the computation, which may increasethe amount of storage required and/or reduce precision given an equalamount of storage to store integer numbers. Many of these disadvantagesare avoided by the use of integer units that perform arithmeticoperations on integer numbers.

Frequently, programmers write programs that process fractional numbers,i.e., numbers that are not whole numbers. The programs may run onprocessors that do not have a floating-point unit or, if they do, theinteger instructions executed by the integer units of the processor maybe faster. To take advantage of potential performance advantagesassociated with integer units, the programmer employs what is commonlyknown as fixed-point arithmetic on fixed-point numbers. Such programsinclude instructions that execute on integer units to process integernumbers, or integer data. The software is aware that the data isfractional and includes instructions that perform operations on theinteger data to deal with the fact that the data is actually fractional,e.g., alignment shifts. Essentially, the fixed-point software manuallyperforms some or all of the functionality that a floating-point unitperforms.

As used in the present disclosure, a “fixed-point” number (or value oroperand or input or output) is a number whose bits of storage areunderstood to include bits that represent a fractional portion of thefixed-point number, referred to herein as “fractional bits.” The bits ofstorage of the fixed-point number are comprised in a memory or register,e.g., an 8-bit or 16-bit word in a memory or register. Furthermore, thebits of storage of the fixed-point number are all used to represent amagnitude, and in some cases a bit is used to represent a sign, but noneof the storage bits of the fixed-point number are used to represent anexponent of the number. Furthermore, the number of fractional bits, orbinary point location, of the fixed-point number is specified in storagethat is distinct from the storage bits of the fixed-point number andthat in a shared, or global, fashion indicates the number of fractionalbits, or binary point location, for a set of fixed-point numbers towhich the fixed-point number belongs, such as the set of input operands,accumulated values or output results of an array of processing units,for example.

Advantageously, embodiments are described herein in which the ALUs areinteger units, but the activation function units include fixed-pointarithmetic hardware assist, or acceleration. This enables the ALUportions to be smaller and faster, which facilitates having more ALUswithin a given space on the die. This implies more neurons per diespace, which is particularly advantageous in a neural network unit.

Furthermore advantageously, in contrast to floating-point numbers thatrequire exponent storage bits for each floating-point number,embodiments are described in which fixed-point numbers are representedwith an indication of the number of bits of storage that are fractionalbits for an entire set of numbers, however, the indication is located ina single, shared storage that globally indicates the number offractional bits for all the numbers of the entire set, e.g., a set ofinputs to a series of operations, a set of accumulated values of theseries, a set of outputs. Preferably, the user of the NNU is enabled tospecify the number of fractional storage bits for the set of numbers.Thus, it should be understood that although in many contexts (e.g.,common mathematics) the term “integer” refers to a signed whole number,i.e., a number not having a fractional portion, the term “integer” inthe present context may refer to numbers having a fractional portion.Furthermore, the term “integer” in the present context is intended todistinguish from floating-point numbers for whom a portion of the bitsof their individual storage are used to represent an exponent of thefloating-point number. Similarly, an integer arithmetic operation, suchas an integer multiply or add or compare performed by an integer unit,assumes the operands do not have an exponent and therefore the integerelements of the integer unit, e.g., integer multiplier, integer adder,integer comparator, do not include logic to deal with exponents, e.g.,do not shift mantissas to align binary points for addition or compareoperations, do not add exponents for multiply operations.

Additionally, embodiments are described herein that include a largehardware integer accumulator to accumulate a large series of integeroperations (e.g., on the order of 1000 multiply-accumulates) withoutloss of precision. This enables the NNU to avoid dealing withfloating-point numbers while at the same time retaining full precisionin the accumulated values without having to saturate them or incurinaccurate results due to overflows. Once the series of integeroperations has accumulated a result into the full precision accumulator,the fixed-point hardware assist performs the necessary scaling andsaturating to convert the full-precision accumulated value to an outputvalue using the user-specified indications of the number of fractionalbits of the accumulated value and the desired number of fractional bitsin the output value, as described in more detail below.

As described in more detail below, preferably the activation functionunits may selectively perform stochastic rounding on the accumulatorvalue when compressing it from its full precision form for use as aninput to an activation function or for being passed through. Finally,the NPUs may be selectively instructed to apply different activationfunctions and/or output a variety of different forms of the accumulatorvalue as dictated by the different needs of a given layer of a neuralnetwork.

Referring now to FIG. 29A, a block diagram illustrating an embodiment ofthe control register 127 of FIG. 1 is shown. The control register 127may include a plurality of control registers 127. The control register127 includes the following fields, as shown: configuration 2902, signeddata 2912, signed weight 2914, data binary point 2922, weight binarypoint 2924, ALU function 2926, round control 2932, activation function2934, reciprocal 2942, shift amount 2944, output RAM 2952, output binarypoint 2954, and output command 2956. The control register 127 values maybe written by both an MTNN instruction 1400 and an instruction of an NNUprogram, such as an initiate instruction.

The configuration 2902 value specifies whether the NNU 121 is in anarrow configuration, a wide configuration or a funnel configuration, asdescribed above. The configuration 2902 implies the size of the inputwords received from the data RAM 122 and the weight RAM 124. In thenarrow and funnel configurations, the size of the input words is narrow(e.g., 8 bits or 9 bits), whereas in the wide configuration, the size ofthe input words is wide (e.g., 12 bits or 16 bits). Furthermore, theconfiguration 2902 implies the size of the output result 133, which isthe same as the input word size.

The signed data value 2912, if true, indicates the data words receivedfrom the data RAM 122 are signed values, and if false, indicates theyare unsigned values. The signed weight value 2914, if true, indicatesthe weight words received from the weight RAM 124 are signed values, andif false, indicates they are unsigned values.

The data binary point 2922 value indicates the location of the binarypoint for the data words received from the data RAM 122. Preferably, thedata binary point 2922 value indicates the number of bit positions fromthe right for the location of the binary point. Stated alternatively,the data binary point 2922 indicates how many of the least significantbits of the data word are fractional bits, i.e., to the right of thebinary point. Similarly, the weight binary point 2924 value indicatesthe location of the binary point for the weight words received from theweight RAM 124. Preferably, when the ALU function 2926 is a multiply andaccumulate or output accumulator, then the NPU 126 determines the numberof bits to the right of the binary point for the value held in theaccumulator 202 as the sum of the data binary point 2922 and the weightbinary point 2924. Thus, for example, if the value of the data binarypoint 2922 is 5 and the value of the weight binary point 2924 is 3, thenthe value in the accumulator 202 has 8 bits to the right of the binarypoint. When the ALU function 2926 is a sum/maximum accumulator anddata/weight word or pass through data/weight word, the NPU 126determines the number of bits to the right of the binary point for thevalue held in the accumulator 202 as the data/weight binary point2922/2924, respectively. In an alternate embodiment, described belowwith respect to FIG. 29B, rather than specifying an individual databinary point 2922 and weight binary point 2924, a single accumulatorbinary point 2923 is specified.

The ALU function 2926 specifies the function performed by the ALU 204 ofthe NPU 126. As described above, the ALU functions 2926 may include, butare not limited to: multiply data word 209 and weight word 203 andaccumulate product with accumulator 202; sum accumulator 202 and weightword 203; sum accumulator 202 and the data word 209; maximum ofaccumulator 202 and data word 209; maximum of accumulator 202 and weightword 203; output accumulator 202; pass through data word 209; passthrough weight word 203; output zero. In one embodiment, the ALUfunction 2926 is specified by an NNU initiate instruction and used bythe ALU 204 in response to an execute instruction (not shown). In oneembodiment, the ALU function 2926 is specified by individual NNUinstructions, such as the multiply-accumulate and maxwacc instructionsdescribed above.

The round control 2932 specifies which form of rounding is to be used bythe rounder 3004 (of FIG. 30). In one embodiment, the rounding modesthat may be specified include, but are not limited to: no rounding,round to nearest, and stochastic rounding. Preferably, the processor 100includes a random bit source 3003 (of FIG. 30) that generates randombits 3005 that are sampled and used to perform the stochastic roundingto reduce the likelihood of a rounding bias. In one embodiment, when theround bit 3005 is one and the sticky bit is zero, the NPU 126 rounds upif the sampled random bit 3005 is true and does not round up if therandom bit 3005 is false. In one embodiment, the random bit source 3003generates the random bits 3005 based on a sampling of random electricalcharacteristics of the processor 100, such as thermal noise across asemiconductor diode or resistor, although other embodiments arecontemplated.

The activation function 2934 specifies the function applied to theaccumulator 202 value 217 to generate the output 133 of the NPU 126. Asdescribed above and below in more detail, the activation functions 2934include, but are not limited to: sigmoid; hyperbolic tangent; softplus;rectify; divide by specified power of two; multiply by a user-specifiedreciprocal value to accomplish an effective division; pass-through fullaccumulator; and pass-through the accumulator as a canonical size, whichis described in more detail below. In one embodiment, the activationfunction is specified by an NNU activation function instruction.Alternatively, the activation function is specified by the initiateinstruction and applied in response to an output instruction, e.g.,write AFU output instruction at address 4 of FIG. 4, in which embodimentthe activation function instruction at address 3 of FIG. 4 is subsumedby the output instruction.

The reciprocal 2942 value specifies a value that is multiplied by theaccumulator 202 value 217 to accomplish a divide of the accumulator 202value 217. That is, the user specifies the reciprocal 2942 value as thereciprocal of the actual desired divisor. This is useful, for example,in conjunction with convolution and pooling operations, as describedherein. Preferably, the user specifies the reciprocal 2942 value in twoparts, as described in more detail with respect to FIG. 29C below. Inone embodiment, the control register 127 includes a field (not shown)that enables the user to specify division by one of a plurality ofbuilt-in divisor values that are the size of commonly used convolutionkernels, e.g., 9, 25, 36 or 49. In such an embodiment, the AFU 212 maystore reciprocals of the built-in divisors for multiplication by theaccumulator 202 value 217.

The shift amount 2944 specifies a number of bits that a shifter of theAFU 212 shifts the accumulator 202 value 217 right to accomplish adivide by a power of two. This may also be useful in conjunction withconvolution kernels whose size is a power of two.

The output RAM 2952 value specifies which of the data RAM 122 and theweight RAM 124 is to receive the output result 133.

The output binary point 2954 value indicates the location of the binarypoint for the output result 133. Preferably, the output binary point2954 indicates the number of bit positions from the right for thelocation of the binary point for the output result 133. Statedalternatively, the output binary point 2954 indicates how many of theleast significant bits of the output result 133 are fractional bits,i.e., to the right of the binary point. The AFU 212 performs rounding,compression, saturation and size conversion based on the value of theoutput binary point 2954 (as well as, in most cases, based on the valueof the data binary point 2922, the weight binary point 2924, theactivation function 2934, and/or the configuration 2902).

The output command 2956 controls various aspects of the output result133. In one embodiment, the AFU 212 employs the notion of a canonicalsize, which is twice the size (in bits) of the width specified by theconfiguration 2902. Thus, for example, if the configuration 2902 impliesthe size of the input words received from the data RAM 122 and theweight RAM 124 are 8 bits, then the canonical size is 16 bits; foranother example, if the configuration 2902 implies the size of the inputwords received from the data RAM 122 and the weight RAM 124 are 16 bits,then the canonical size is 32 bits. As described herein, the size of theaccumulator 202 is large (e.g., the narrow accumulator 202B is 28 bitsand the wide accumulator 202A is 41 bits) in order to preserve fullprecision of the intermediate computations, e.g., 1024 and 512 NNUmultiply-accumulate instructions, respectively. Consequently, theaccumulator 202 value 217 is larger (in bits) than the canonical size,and the AFU 212 (e.g., CCS 3008 described below with respect to FIG.30), for most values of the activation function 2934 (except forpass-through full accumulator), compresses the accumulator 202 value 217down to a value that is the canonical size. A first predetermined valueof the output command 2956 instructs the AFU 212 to perform thespecified activation function 2934 to generate an internal result thatis the same size as the original input words, i.e., half the canonicalsize, and to output the internal result as the output result 133. Asecond predetermined value of the output command 2956 instructs the AFU212 to perform the specified activation function 2934 to generate aninternal result that is twice the size as the original input words,i.e., the canonical size, and to output the lower half of the internalresult as the output result 133; and a third predetermined value of theoutput command 2956 instructs the AFU 212 to output the upper half ofthe canonical size internal result as the output result 133. A fourthpredetermined value of the output command 2956 instructs the AFU 212 tooutput the raw least-significant word (whose width specified by theconfiguration 2902) of the accumulator 202 as the output result 133; afifth predetermined value instructs the AFU 212 to output the rawmiddle-significant word of the accumulator 202 as the output result 133;and a sixth predetermined value instructs the AFU 212 to output the rawmost-significant word of the accumulator 202 as the output result 133,as described above with respect to FIGS. 8 through 10. As describedabove, outputting the full accumulator 202 size or the canonical sizeinternal result may be advantageous, for example, for enabling otherexecution units 112 of the processor 100 to perform activationfunctions, such as the softmax activation function.

Although the fields of FIG. 29A (and FIGS. 29B and 29C) are described asresiding in the control register 127, in other embodiments one or moreof the fields may reside in other parts of the NNU 121. Preferably, manyof the fields are included in the NNU instructions themselves anddecoded by the sequencer 128 to generate to a micro-operation 3416 (ofFIG. 34) that controls the ALUs 204 and/or AFUs 212. Additionally, thefields may be included in a micro-operation 3414 (of FIG. 34) stored ina media register 118 that controls the ALUs 204 and/or AFUs 212. In suchembodiments, the use of the initialize NNU instruction is minimized, andin other embodiments the initialize NNU instruction is eliminated.

As described above, an NNU instruction is capable of specifying toperform ALU operations on memory operands (e.g., word from data RAM 122and/or weight RAM 124) or a rotated operand (e.g., from the mux-regs208/705). In one embodiment, an NNU instruction may also specify anoperand as a registered output of an activation function (e.g., theoutput of register 3038 of FIG. 30). Additionally, as described above,an NNU instruction is capable of specifying to increment a current rowaddress of the data RAM 122 or weight RAM 124. In one embodiment, theNNU instruction may specify an immediate signed integer delta value thatis added to the current row to accomplish incrementing or decrementingby a value other than one.

Referring now to FIG. 29B, a block diagram illustrating an embodiment ofthe control register 127 of FIG. 1 according to an alternate embodimentis shown. The control register 127 of FIG. 29B is similar to the controlregister 127 of FIG. 29A; however, the control register 127 of FIG. 29Bincludes an accumulator binary point 2923. The accumulator binary point2923 indicates the location of the binary point for the accumulator 202.Preferably, the accumulator binary point 2923 value indicates the numberof bit positions from the right for the location of the binary point.Stated alternatively, the accumulator binary point 2923 indicates howmany of the least significant bits of the accumulator 202 are fractionalbits, i.e., to the right of the binary point. In this embodiment, theaccumulator binary point 2923 is specified explicitly, rather than beingdetermined implicitly, as described above with respect to the embodimentof FIG. 29A.

Referring now to FIG. 29C, a block diagram illustrating an embodiment ofthe reciprocal 2942 of FIG. 29A stored as two parts according to oneembodiment is shown. A first part 2962 is a shift value that indicatesthe number of suppressed leading zeroes 2962 in the true reciprocalvalue that the user desires to be multiplied by the accumulator 202value 217. The number of leading zeroes is the number of consecutivezeroes immediately to the right of the binary point. The second part2694 is the leading zero-suppressed reciprocal 2964 value, i.e., thetrue reciprocal value with all leading zeroes removed. In oneembodiment, the number of suppressed leading zeroes 2962 is stored asfour bits and the leading zero-suppressed reciprocal 2964 value isstored as 8-bit unsigned value.

To illustrate by example, assume the user desires the accumulator 202value 217 to be multiplied by the reciprocal of 49. The binaryrepresentation of the reciprocal of 49 represented with 13 fractionalbits is 0.0000010100111, which has five leading zeroes. In this case,the user populates the number of suppressed leading zeroes 2962 with avalue of five, and populates the leading zero-suppressed reciprocal 2964with a value of 10100111. After the reciprocal multiplier “divider A”3014 (of FIG. 30) multiplies the accumulator 202 value 217 and theleading zero-suppressed reciprocal 2964 value, it right-shifts theresulting product by the number of suppressed leading zeroes 2962. Suchan embodiment may advantageously accomplish high precision with arelatively small number of bits used to represent the reciprocal 2942value.

Referring now to FIG. 30, a block diagram illustrating in more detail anembodiment of an AFU 212 of FIG. 2 is shown. The AFU 212 includes thecontrol register 127 of FIG. 1; a positive form converter (PFC) andoutput binary point aligner (OBPA) 3002 that receives the accumulator202 value 217; a rounder 3004 that receives the accumulator 202 value217 and indication of the number of bits shifted out by the OBPA 3002; arandom bit source 3003 that generates random bits 3005, as describedabove; a first mux 3006 that receives the output of the PFC and OBPA3002 and the output of the rounder 3004; a compressor to canonical size(CCS) and saturator 3008 that receives the output of the first mux 3006;a bit selector and saturator 3012 that receives the output of the CCSand saturator 3008; a rectifier 3018 that receives the output of the CCSand saturator 3008; a reciprocal multiplier 3014 that receives theoutput of the CCS and saturator 3008; a right shifter 3016 that receivesthe output of the CCS and saturator 3008; a hyperbolic tangent (tanh)module 3022 that receives the output of the bit selector and saturator3012; a sigmoid module 3024 that receives the output of the bit selectorand saturator 3012; a softplus module 3026 that receives the output ofthe bit selector and saturator 3012; a second mux 3032 that receives theoutputs of the tanh module 3022, the sigmoid module 3024, the softplusmodule 3026, the rectifier 3108, the reciprocal multiplier 3014, theright shifter 3016 and the passed-through canonical size output 3028 ofthe CCS and saturator 3008; a sign restorer 3034 that receives theoutput of the second mux 3032; a size converter and saturator 3036 thatreceives the output of the sign restorer 3034; a third mux 3037 thatreceives the output of the size converter and saturator 3036 and theaccumulator output 217; and an output register 3038 that receives theoutput of the mux 3037 and whose output is the result 133 of FIG. 1.

The PFC and OBPA 3002 receive the accumulator 202 value 217. Preferably,the accumulator 202 value 217 is a full precision value, as describedabove. That is, the accumulator 202 has a sufficient number of bits ofstorage to hold an accumulated value that is the sum, generated by theinteger adder 244, of a series of products generated by the integermultiplier 242 without discarding any of the bits of the individualproducts of the multiplier 242 or sums of the adder 244 so that there isno loss of precision. Preferably, the accumulator 202 has at least asufficient number of bits to hold the maximum number of accumulations ofthe products that an NNU 121 is programmable to perform. For example,referring to the program of FIG. 4 to illustrate, the maximum number ofproduct accumulations the NNU 121 is programmable to perform when in awide configuration is 512, and the accumulator 202 bit width is 41. Foranother example, referring to the program of FIG. 20 to illustrate, themaximum number of product accumulations the NNU 121 is programmable toperform when in a narrow configuration is 1024, and the accumulator 202bit width is 28. To generalize, the full precision accumulator 202includes at least Q bits, where Q is the sum of M and log₂P, where M isthe bit width of the integer product of the multiplier 242 (e.g., 16bits for a narrow multiplier 242, or 32 bits for a wide multiplier 242)and P is the maximum permissible number of the integer products that maybe accumulated into the accumulator 202. Preferably, the maximum numberof product accumulations is specified via a programming specification tothe programmer of the NNU 121. In one embodiment, the sequencer 128enforces a maximum value of the count of a multiply-accumulate NNUinstruction (e.g., the instruction at address 2 of FIG. 4), for example,of 511, with the assumption of one previous multiply-accumulateinstruction that loads the row of data/weight words 206/207 from thedata/weight RAM 122/124 (e.g., the instruction at address 1 of FIG. 4).

Advantageously, by including an accumulator 202 that has a large enoughbit width to accumulate a full precision value for the maximum number ofallowable accumulations, this simplifies the design of the ALU 204portion of the NPU 126. In particular, it alleviates the need for logicto saturate sums generated by the integer adder 244 that would overflowa smaller accumulator and that would need to keep track of the binarypoint location of the accumulator to determine whether an overflow hasoccurred to know whether a saturation was needed. To illustrate byexample a problem with a design that included a non-full precisionaccumulator and instead includes saturating logic to handle overflows ofthe non-full precision accumulator, assume the following.

(1) The range of the data word values is between 0 and 1 and all thebits of storage are used to store fractional bits. The range of theweight words is between −8 and +8 and all but three of the bits ofstorage are used to store fractional bits. And, the range of theaccumulated values for input to a hyperbolic tangent activation functionis between −8 and +8 and all but three of the bits of storage are usedto store fractional bits.

(2) The bit width of the accumulator is non-full precision (e.g., onlythe bit width of the products).

(3) The final accumulated value would be somewhere between −8 and +8(e.g., +4.2), assuming the accumulator were full precision; however, theproducts before a “point A” in the series tend to be positive much morefrequently, whereas the products after point A tend to be negative muchmore frequently.

In such a situation, an inaccurate result (i.e., a result other than+4.2) might be obtained. This is because at some point before point Athe accumulator may be saturated to the maximum+8 value when it shouldhave been a larger value, e.g., +8.2, causing loss of the remaining+0.2.The accumulator could even remain at the saturated value for moreproduct accumulations resulting in loss of even more positive value.Thus, the final value of the accumulator could be a smaller number thanit would have been (i.e., less than +4.2) if the accumulator had a fullprecision bit width.

The PFC 3002 converts the accumulator 202 value 217 to a positive form,if the value is negative, and generates an additional bit that indicateswhether the original value was positive or negative, which is passeddown the AFU 212 pipeline along with the value. Converting to a positiveform simplifies subsequent operations by the AFU 212. For example, itenables only positive values to be inputted to the tanh 3022 and sigmoid3024 modules, thus simplifying them. Additionally, it simplifies therounder 3004 and the saturator 3008.

The OBPA 3002 shifts, or scales, the positive-form value right to alignit with the output binary point 2954 specified in the control register127. Preferably, the OBPA 3002 calculates the shift amount as adifference that is the number of fractional bits of the output (e.g.,specified by the output binary point 2954) subtracted from the number offractional bits of the accumulator 202 value 217 (e.g., specified by theaccumulator binary point 2923 or the sum of the data binary point 2922and the weight binary point 2924). Thus, for example, if the accumulator202 binary point 2923 is 8 (as in the example above) and the outputbinary point 2954 is 3, then the OBPA 3002 shifts the positive-formvalue right 5 bits to generate a result provided to the mux 3006 and tothe rounder 3004.

The rounder 3004 rounds the accumulator 202 value 217. Preferably, therounder 3004 generates a rounded version of the positive-form valuegenerated by the PFC and OBPA 3002 and provides the rounded version tothe mux 3006. The rounder 3004 rounds according to the round control2932 described above, which may include stochastic rounding using therandom bit 3005, as described above and below. The mux 3006 selects oneof its inputs, i.e., either the positive-form value from the PFC andOBPA 3002 or the rounded version thereof from the rounder 3004, based onthe round control 2932 (which may include stochastic rounding, asdescribed herein) and provides the selected value to the CCS andsaturator 3008. Preferably, if the round control 2932 specifies norounding, then the mux 3006 selects the output of the PFC and OBPA 3002,and otherwise selects the output of the rounder 3004. Other embodimentsare contemplated in which the AFU 212 performs additional rounding. Forexample, in one embodiment, the bit selector 3012 rounds based on lostlow-order bits when it compresses the bits of the CCS and saturator 3008output (described below). For another example, in one embodiment, theproduct of the reciprocal multiplier 3014 (described below) is rounded.For yet another example, in one embodiment, the size converter 3036rounds when it converts to the proper output size (described below),which may involve losing low-order bits used in the roundingdetermination.

The CCS 3008 compresses the mux 3006 output value to the canonical size.Thus, for example, if the NPU 126 is in a narrow or funnel configuration2902, then the CCS 3008 compresses the 28-bit mux 3006 output value to16 bits; and if the NPU 126 is in a wide configuration 2902, then theCCS 3008 compresses the 41-bit mux 3006 output value to 32 bits.However, before compressing to the canonical size, if the pre-compressedvalue is greater than the maximum value expressible in the canonicalform, the saturator 3008 saturates the pre-compressed value to themaximum value expressible in the canonical form. For example, if any ofthe bits of the pre-compressed value left of the most-significantcanonical form bit has a 1 value, then the saturator 3008 saturates tothe maximum value (e.g., to all 1's).

Preferably, the tanh 3022, sigmoid 3024 and softplus 3026 modulescomprise lookup tables, e.g., programmable logic arrays (PLA), read-onlymemories (ROM), combinational logic gates, and so forth. In oneembodiment, in order to simplify and reduce the size of the modules3022/3024/3026, they are provided an input value that has 3.4 form,i.e., three whole bits and four fractional bits, i.e., the input valuehas four bits to the right of the binary point and three bits to theleft of the binary point. These values are chosen because at theextremes of the input value range (−8, +8) of the 3.4 form, the outputvalues asymptotically approach their minimum/maximum values. However,other embodiments are contemplated that place the binary point at adifferent location, e.g., in a 4.3 form or a 2.5 form. The bit selector3012 selects the bits of the CCS and saturator 3008 output that satisfythe 3.4 form criteria, which involves compression, i.e., some bits arelost, since the canonical form has a larger number of bits. However,prior to selecting/compressing the CCS and saturator 3008 output value,if the pre-compressed value is greater than the maximum valueexpressible in the 3.4 form, the saturator 3012 saturates thepre-compressed value to the maximum value expressible in the 3.4 form.For example, if any of the bits of the pre-compressed value left of themost-significant 3.4 form bit has a 1 value, then the saturator 3012saturates to the maximum value (e.g., to all 1's).

The tanh 3022, sigmoid 3024 and softplus 3026 modules perform theirrespective activation functions (described above) on the 3.4 form valueoutput by the CCS and saturator 3008 to generate a result. Preferably,the result of the tanh 3022 and sigmoid 3024 modules is a 7-bit resultin a 0.7 form, i.e., zero whole bits and seven fractional bits, i.e.,the input value has seven bits to the right of the binary point.Preferably, the result of the softplus module 3026 is a 7-bit result ina 3.4 form, e.g., in the same form as the input to the module 3026.Preferably, the outputs of the tanh 3022, sigmoid 3024 and softplus 3026modules are extended to canonical form (e.g., leading zeroes added asnecessary) and aligned to have the binary point specified by the outputbinary point 2954 value.

The rectifier 3018 generates a rectified version of the output value ofthe CCS and saturator 3008. That is, if the output value of the CCS andsaturator 3008 (its sign is piped down as describe above) is negative,the rectifier 3018 outputs a value of zero; otherwise, the rectifier3018 outputs its input value. Preferably, the output of the rectifier3018 is in canonical form and has the binary point specified by theoutput binary point 2954 value.

The reciprocal multiplier 3014 multiplies the output of the CCS andsaturator 3008 by the user-specified reciprocal value specified in thereciprocal value 2942 to generate its canonical size product, which iseffectively the quotient of the output of the CCS and saturator 3008 andthe divisor that is the reciprocal of the reciprocal 2942 value.Preferably, the output of the reciprocal multiplier 3014 is in canonicalform and has the binary point specified by the output binary point 2954value.

The right shifter 3016 shifts the output of the CCS and saturator 3008by the user-specified number of bits specified in the shift amount value2944 to generate its canonical size quotient. Preferably, the output ofthe right shifter 3016 is in canonical form and has the binary pointspecified by the output binary point 2954 value.

The mux 3032 selects the appropriate input specified by the activationfunction 2934 value and provides the selection to the sign restorer3034, which converts the positive form output of the mux 3032 to anegative form if the original accumulator 202 value 217 was a negativevalue, e.g., to two's-complement form.

The size converter 3036 converts the output of the sign restorer 3034 tothe proper size based on the value of the output command 2956, whichvalues are described above with respect to FIG. 29A. Preferably, theoutput of the sign restorer 3034 has a binary point specified by theoutput binary point 2954 value. Preferably, for the first predeterminedvalue of the output command 2956, the size converter 3036 discards thebits of the upper half of the sign restorer 3034 output. Furthermore, ifthe output of the sign restorer 3034 is positive and exceeds the maximumvalue expressible in the word size specified by the configuration 2902or is negative and is less than the minimum value expressible in theword size, the saturator 3036 saturates its output to the respectivemaximum/minimum value expressible in the word size. For the second andthird predetermined values, the size converter 3036 passes through thesign restorer 3034 output.

The mux 3037 selects either the size converter and saturator 3036 outputor the accumulator 202 output 217, based on the output command 2956, forprovision to the output register 3038. More specifically, for the firstand second predetermined values of the output command 2956, the mux 3037selects the lower word (whose size is specified by the configuration2902) of the output of the size converter and saturator 3036. For thethird predetermined value, the mux 3037 selects the upper word of theoutput of the size converter and saturator 3036. For the fourthpredetermined value, the mux 3037 selects the lower word of the rawaccumulator 202 value 217; for the fifth predetermined value, the mux3037 selects the middle word of the raw accumulator 202 value 217; andfor the sixth predetermined value, the mux 3037 selects the upper wordof the raw accumulator 202 value 217. As describe above, preferably theAFU 212 pads the upper bits of the upper word of the raw accumulator 202value 217 to zero.

Referring now to FIG. 31, an example of operation of the AFU 212 of FIG.30 is shown. As shown, the configuration 2902 is set to a narrowconfiguration of the NPUs 126. Additionally, the signed data 2912 andsigned weight 2914 values are true. Additionally, the data binary point2922 value indicates the binary point for the data RAM 122 words islocated such that there are 7 bits to the right of the binary point, andan example value of the first data word received by one of the NPUs 126is shown as 0.1001110. Still further, the weight binary point 2924 valueindicates the binary point for the weight RAM 124 words is located suchthat there are 3 bits to the right of the binary point, and an examplevalue of the first weight word received by the one of the NPUs 126 isshown as 00001.010.

The 16-bit product (which is accumulated with the initial zero value ofthe accumulator 202) of the first data and weight words is shown as000000.1100001100. Because the data binary point 2912 is 7 and theweight binary point 2914 is 3, the implied accumulator 202 binary pointis located such that there are 10 bits to the right of the binary point.In the case of a narrow configuration, the accumulator 202 is 28 bitswide, in the example embodiment. In the example, a value 217 of000000000000000001.1101010100 of the accumulator 202 after all the ALUoperations (e.g., all 1024 multiply-accumulates of FIG. 20) areperformed is shown.

The output binary point 2954 value indicates the binary point for theoutput is located such that there are 7 bits to the right of the binarypoint. Therefore, after passing through the OBPA 3002 and CCS 3008, theaccumulator 202 value 217 is scaled, rounded and compressed to thecanonical form value of 000000001.1101011. In the example, the outputbinary point location indicates 7 fractional bits, and the accumulator202 binary point location indicates 10 fractional bits. Therefore, theOBPA 3002 calculates a difference of 3 and scales the accumulator 202value 217 by shifting it right 3 bits. This is indicated in FIG. 31 bythe loss of the 3 least significant bits (binary 100) of the accumulator202 value 217. Further in the example, the round control 2932 valueindicates to use stochastic rounding, and in the example it is assumedthat the sampled random bit 3005 is true. Consequently, the leastsignificant bit was rounded up because the round bit of the accumulator202 value 217 (most significant bit of the 3 bits shifted out by thescaling of the accumulator 202 value 217) was one and the sticky bit(Boolean OR of the 2 least significant bits of the 3 bits shifted out bythe scaling of the accumulator 202 value 217) was zero, according to thedescription above.

The activation function 2934 indicates to use a sigmoid function, in theexample. Consequently, the bit selector 3012 selects the bits of thecanonical form value such that the input to the sigmoid module 3024 hasthree whole bits and four fractional bits, as described above, i.e., avalue of 001.1101, as shown. The sigmoid module 3024 outputs a valuethat is put in canonical form as shown of 000000000.1101110.

The output command 2956 in the example specifies the first predeterminedvalue, i.e., to output the word size indicated by the configuration2902, which in this case is a narrow word (8 bits). Consequently, thesize converter 3036 converts the canonical sigmoid output value to an 8bit quantity having an implied binary point located such that 7 bits areto the right of the binary point, yielding an output value of 01101110,as shown.

Referring now to FIG. 32, a second example of operation of the AFU 212of FIG. 30 is shown. The example of FIG. 32 illustrates operation of theAFU 212 when the activation function 2934 indicates to pass-through theaccumulator 202 value 217 in the canonical size. As shown, theconfiguration 2902 is set to a narrow configuration of the NPUs 126.

In the example, the accumulator 202 is 28 bits wide, and the accumulator202 binary point is located such that there are 10 bits to the right ofthe binary point (either because the sum of the data binary point 2912and the weight binary point 2914 is 10 according to one embodiment, orthe accumulator binary point 2923 is explicitly specified as having avalue of 10 according to an alternate embodiment, as described above).In the example, FIG. 32 shows a value 217 of000001100000011011.1101111010 of the accumulator 202 after all the ALUoperations are performed.

In the example, the output binary point 2954 value indicates the binarypoint for the output is located such that there are 4 bits to the rightof the binary point. Therefore, after passing through the OBPA 3002 andCCS 3008, the accumulator 202 value 217 is saturated and compressed tothe canonical form value of 111111111111.1111, as shown, that isreceived by the mux 3032 as the canonical size pass-through value 3028.

In the example, two output commands 2956 are shown. The first outputcommand 2956 specifies the second predetermined value, i.e., to outputthe lower word of the canonical form size. Since the size indicated bythe configuration 2902 is a narrow word (8 bits), which implies acanonical size of 16 bits, the size converter 3036 selects the lower 8bits of the canonical size pass-through value 3028 to yield an 8 bitvalue of 11111111, as shown. The second output command 2956 specifiesthe third predetermined value, i.e., to output the upper word of thecanonical form size. Consequently, the size converter 3036 selects theupper 8 bits of the canonical size pass-through value 3028 to yield an 8bit value of 11111111, as shown.

Referring now to FIG. 33, a third example of operation of the AFU 212 ofFIG. 30 is shown. The example of FIG. 33 illustrates operation of theAFU 212 when the activation function 2934 indicates to pass-through thefull raw accumulator 202 value 217. As shown, the configuration 2902 isset to a wide configuration of the NPUs 126 (e.g., 16-bit input words).

In the example, the accumulator 202 is 41 bits wide, and the accumulator202 binary point is located such that there are 8 bits to the right ofthe binary point (either because the sum of the data binary point 2912and the weight binary point 2914 is 8 according to one embodiment, orthe accumulator binary point 2923 is explicitly specified as having avalue of 8 according to an alternate embodiment, as described above). Inthe example, FIG. 33 shows a value 217 of001000000000000000001100000011011.11011110 of the accumulator 202 afterall the ALU operations are performed.

In the example, three output commands 2956 are shown. The first outputcommand 2956 specifies the fourth predetermined value, i.e., to outputthe lower word of the raw accumulator 202 value; the second outputcommand 2956 specifies the fifth predetermined value, i.e., to outputthe middle word of the raw accumulator 202 value; and the third outputcommand 2956 specifies the sixth predetermined value, i.e., to outputthe upper word of the raw accumulator 202 value. Since the sizeindicated by the configuration 2902 is a wide word (16 bits), FIG. 33shows that in response to the first output command 2956, the mux 3037selects the 16-bit value of 0001101111011110; in response to the secondoutput command 2956, the mux 3037 selects the 16-bit value of0000000000011000; and in response to the third output command 2956, themux 3037 selects the 16-bit value of 0000000001000000.

As discussed above, advantageously the NNU 121 operates on integer datarather than floating-point data. This has the advantage of simplifyingeach NPU 126, or at least the ALU 204 portion. For example, the ALU 204need not include adders that would be needed in a floating-pointimplementation to add the exponents of the multiplicands for themultiplier 242. Similarly, the ALU 204 need not include shifters thatwould be needed in a floating-point implementation to align binarypoints of the addends for the adder 234. As one skilled in the art willappreciate, floating point units are generally very complex; thus, theseare only examples of simplifications to the ALU 204, and othersimplifications are enjoyed by the instant integer embodiments withhardware fixed-point assist that enable the user to specify the relevantbinary points. The fact that the ALUs 204 are integer units mayadvantageously result in a smaller (and faster) NPU 126 than afloating-point embodiment, which further advantageously facilitates theincorporation of a large array of NPUs 126 into the NNU 121. The AFU 212portion deals with scaling and saturating the accumulator 202 value 217based on the, preferably user-specified, number of fractional bitsdesired in the accumulated value and number of fractional bits desiredin the output value. Advantageously, any additional complexity andaccompanying increase in size, power consumption and/or time in thefixed-point hardware assist of the AFUs 212 may be amortized by sharingthe AFUs 212 among the ALU 204 portions, as described with respect tothe embodiment of FIG. 11, for example, since the number of AFUs 1112may be reduced in a shared embodiment.

Advantageously, embodiments described herein enjoy many of the benefitsassociated with reduced complexity of hardware integer arithmetic unitsover floating-point arithmetic units, while still providing arithmeticoperations on fractional numbers, i.e., numbers with a binary point. Anadvantage of floating-point arithmetic is that it accommodatesarithmetic operations on data whose individual values may be anywherewithin a very wide range of values (which is effectively limited only bythe size of the exponent range, which may be very large). That is, eachfloating-point number has its own potentially unique exponent value.However, embodiments are described here that recognize and takeadvantage of the fact that there are certain applications in which theinput data is highly parallelized and whose values are within arelatively narrow range such that the “exponent” for all theparallelized values can be the same. Therefore, the embodiments enablethe user to specify the binary point location once for all the inputvalues and/or accumulated values. Similarly, the embodiments enable theuser to specify the binary point location once for all the outputvalues, recognizing and taking advantage of similar rangecharacteristics of the parallelized outputs. An artificial neuralnetwork is an example of such an application, although the embodimentsmay be employed to perform computations for other applications. Byspecifying the binary point location for the inputs once, rather thanfor each individual input number, the embodiments provide more efficientuse of memory space (e.g., require less memory) over a floating-pointimplementation and/or provide an increase in precision for a similaramount of memory since the bits that would be used for an exponent in afloating-point implementation can be used to specify more precision inthe magnitude.

Further advantageously, the embodiments recognize the potential loss ofprecision that could be experienced during the accumulation of a largeseries of integer operations (e.g., overflow or loss of fractional bitsof lesser significance) and provide a solution, primarily in the form ofa sufficiently large accumulator to avoid loss of precision.

Direct Execution of NNU Micro-Operation

Referring now to FIG. 34, a block diagram illustrating the processor 100of FIG. 1 and in more detail portions of the NNU 121 of FIG. 1 is shown.The NNU 121 includes pipeline stages 3401 of the NPUs 126. The pipelinestages 3401, separated by staging registers, include combinatorial logicthat accomplish the operation of the NPUs 126 as described herein, suchas Boolean logic gates, multiplexers, adders, multipliers, comparators,and so forth. The pipeline stages 3401 receive a micro-operation 3418from a mux 3402. The micro-operation 3418 flows down the pipeline stages3401 and controls their combinatorial logic. The micro-operation 3418 isa collection of bits. Preferably the micro-operation 3418 includes thebits of the data RAM 122 memory address 123, the weight RAM 124 memoryaddress 125, the program memory 129 memory address 131, the mux-reg208/705 control signals 213/713, the mux 802 control signals 803, andmany of the fields of the control register 127 (e.g., of FIGS. 29Athrough 29C, for example, among others. In one embodiment, themicro-operation 3418 comprises approximately 120 bits. The mux 3402receives a micro-operation from three different sources and selects oneof them as the micro-operation 3418 for provision to the pipeline stages3401.

One micro-operation source to the mux 3402 is the sequencer 128 ofFIG. 1. The sequencer 128 decodes the NNU instructions received from theprogram memory 129 and in response generates a micro-operation 3416provided to a first input of the mux 3402.

A second micro-operation source to the mux 3402 is a decoder 3404 thatreceives microinstructions 105 from a reservation station 108 of FIG. 1,along with operands from the GPR 116 and media registers 118.Preferably, the microinstructions 105 are generated by the instructiontranslator 104 in response to translating MTNN instructions 1400 andMFNN instructions 1500, as described above. The microinstructions 105may include an immediate field that specifies a particular function(which was specified by an MTNN instruction 1400 or an MFNN instruction1500), such as starting and stopping execution of a program in theprogram memory 129, directly executing a micro-operation from the mediaregisters 118, or reading/writing a memory of the NNU 121, as describedabove. The decoder 3404 decodes the microinstructions 105 and inresponse generates a micro-operation 3412 provided to a second input ofthe mux 3402. Preferably, in response to some functions 1432/1532 of anMTNN/MFNN 1400/1500 instruction, it is not necessary for the decoder3404 to generate a micro-operation 3412 to send down the pipeline 3401,for example, writing to the control register 127, starting execution ofa program in the program memory 129, pausing the execution of a programin the program memory 129, waiting for completion of the execution of aprogram in the program memory 129, reading from the status register 127and resetting the NNU 121.

A third micro-operation source to the mux 3402 is the media registers118 themselves. Preferably, as described above with respect to FIG. 14,a MTNN instruction 1400 may specify a function that instructs the NNU121 to directly execute a micro-operation 3414 provided from the mediaregisters 118 to a third input of the mux 3402. The direct execution ofa micro-operation 3414 provided by the architectural media registers 118may be particularly useful for test, e.g., built-in self test (BIST),and debug of the NNU 121.

Preferably, the decoder 3404 generates a mode indicator 3422 thatcontrols the mux 3402 selection. When an MTNN instruction 1400 specifiesa function to start running a program from the program memory 129, thedecoder 3404 generates a mode indicator 3422 value that causes the mux3402 to select the micro-operation 3416 from the sequencer 128 untileither an error occurs or until the decoder 3404 encounters an MTNNinstruction 1400 that specifies a function to stop running a programfrom the program memory 129. When an MTNN instruction 1400 specifies afunction that instructs the NNU 121 to directly execute amicro-operation 3414 provided from a media register 118, the decoder3404 generates a mode indicator 3422 value that causes the mux 3402 toselect the micro-operation 3414 from the specified media register 118.Otherwise, the decoder 3404 generates a mode indicator 3422 value thatcauses the mux 3402 to select the micro-operation 3412 from the decoder3404.

Variable Rate Neural Network Unit

There may be situations in which the NNU 121 runs a program and thensits idle waiting for the processor 100 to do something it needs beforeit can run its next program. For example, assume a situation similar tothat described with respect to FIGS. 3 through 6A in which the NNU 121runs two or more successive instances of amultiply-accumulate-activation function program (which may also bereferred to as a feed forward neural network layer program). It may takethe processor 100 significantly longer to write 512 KB worth of weightvalues into the weight RAM 124 that will be used by the next run of theNNU program than it will take for the NNU 121 to run the program. Statedalternatively, the NNU 121 may run the program in a relatively shortamount of time and then sit idle while the processor 100 finisheswriting the next weight values into the weight RAM 124 for the next runof the program. This situation is visually illustrated in FIG. 36A,which is described in more detail below. In such situations, it may beadvantageous to run the NNU 121 at a slower rate and take longer toexecute the program and thereby spread out over more time the energyconsumption required for the NNU 121 to run the program, which may tendto keep the temperature of the NNU 121 lower and perhaps of theprocessor 100 in general. This situation is referred to as relaxed modeand is visually illustrated in FIG. 36B, which is described in moredetail below.

Referring now to FIG. 35, a block diagram illustrating a processor 100that includes a variable rate NNU 121 is shown. The processor 100 issimilar to the processor 100 of FIG. 1 in many respects andlike-numbered elements are similar. The processor 100 of FIG. 35 alsoincludes clock generation logic 3502 coupled to the functional units ofthe processor 100, namely, the instruction fetch unit 101, theinstruction cache 102, the instruction translator 104, the rename unit106, the reservation stations 108, the NNU 121, the other executionunits 112, the memory subsystem 114, the general purpose registers 116and the media registers 118. The clock generation logic 3502 includes aclock generator, such as a phase-locked loop (PLL), that generates aclock signal having a primary clock rate, or clock frequency. Forexample, the primary clock rate may be 1 GHz, 1.5 GHz, 2 GHz and soforth. The clock rate indicates the number of cycles, e.g., oscillationsbetween a high and low state, of the clock signal per second.Preferably, the clock signal has a balanced duty cycle, i.e., high halfthe cycle and low the other half of the cycle; alternatively, the clocksignal has an unbalanced duty cycle in which the clock signal is in thehigh state longer than it is in the low state, or vice versa.Preferably, the PLL is configurable to generate the primary clock signalat multiple clock rates. Preferably, the processor 100 includes a powermanagement module that automatically adjusts the primary clock ratebased on various factors including the dynamically detected operatingtemperature of the processor 100, utilization, and commands from systemsoftware (e.g., operating system, BIOS) indicating desired performanceand/or power savings indicators. In one embodiment, the power managementmodule includes microcode of the processor 100.

The clock generation logic 3502 also includes a clock distributionnetwork, or clock tree. The clock tree distributes the primary clocksignal to the functional units of the processor 100, which are indicatedin FIG. 35 as clock signal 3506-1 to the instruction fetch unit 101,clock signal 3506-2 to the instruction cache 102, clock signal 3506-10to the instruction translator 104, clock signal 3506-9 to the renameunit 106, clock signal 3506-8 to the reservation stations 108, clocksignal 3506-7 to the NNU 121, clock signal 3506-4 to the other executionunits 112, clock signal 3506-3 to the memory subsystem 114, clock signal3506-5 to the general purpose registers 116 and clock signal 3506-6 tothe media registers 118, and which are referred to collectively as clocksignals 3506. The clock tree includes nodes, or wires, that transmit theprimary clock signals 3506 to their respective functional units.Additionally, preferably the clock generation logic 3502 includes clockbuffers that re-generate the primary clock signal as needed to providecleaner clock signals and/or boost the voltage levels of the primaryclock signal, particularly for long nodes. Additionally, each functionalunit may also include its own sub-clock tree, as needed, thatre-generates and/or boosts the respective primary clock signal 3506 itreceives.

The NNU 121 includes clock reduction logic 3504 that receives a relaxindicator 3512 and that receives the primary clock signal 3506-7 and, inresponse, generates a secondary clock signal. The secondary clock signalhas a clock rate that is either the same clock rate as the primary clockrate or, when in relaxed mode, that is reduced relative to the primaryclock rate by an amount programmed into the relax indicator 3512, whichpotentially provides thermal benefits. The clock reduction logic 3504 issimilar in many respects to the clock generation logic 3502 in that itincludes a clock distribution network, or clock tree, that distributesthe secondary clock signal to various blocks of the NNU 121, which areindicated as clock signal 3508-1 to the array of NPUs 126, clock signal3508-2 to the sequencer 128 and clock signal 3508-3 to the interfacelogic 3514, and which are referred to collectively or individually assecondary clock signal 3508. Preferably, the NPUs 126 include aplurality of pipeline stages 3401, as described with respect to FIG. 34,that include pipeline staging registers that receive the secondary clocksignal 3508-1 from the clock reduction logic 3504.

The NNU 121 also includes interface logic 3514 that receives the primaryclock signal 3506-7 and secondary clock signal 3508-3. The interfacelogic 3514 is coupled between the lower portions of the front end of theprocessor 100 (e.g., the reservation stations 108, media registers 118,and general purpose registers 116) and the various blocks of the NNU121, namely the clock reduction logic 3504, the data RAM 122, the weightRAM 124, the program memory 129 and the sequencer 128. The interfacelogic 3514 includes a data RAM buffer 3522, a weight RAM buffer 3524,the decoder 3404 of FIG. 34 and the relax indicator 3512. The relaxindicator 3512 holds a value that specifies how much slower, if any, thearray of NPUs 126 will execute NNU program instructions. Preferably, therelax indicator 3512 specifies a divisor value, N, by which the clockreduction logic 3504 divides the primary clock signal 3506-7 to generatethe secondary clock signal 3508 such that the secondary clock signal3508 has a rate that is 1/N. Preferably, the value of N may beprogrammed to any one of a plurality of different predetermined valuesto cause the clock reduction logic 3504 to generate the secondary clocksignal 3508 at a corresponding plurality of different rates that areless than the primary clock rate.

In one embodiment, the clock reduction logic 3504 comprises a clockdivider circuit to divide the primary clock signal 3506-7 by the relaxindicator 3512 value. In one embodiment, the clock reduction logic 3504comprises clock gates (e.g., AND gates) that gate the primary clocksignal 3506-7 with an enable signal that is true once only every Ncycles of the primary clock signal 3506-7. For example, a circuit thatincludes a counter that counts up to N may be used to generate theenable signal. When accompanying logic detects the output of the countermatches N, the logic generates a true pulse on the secondary clocksignal 3508 and resets the counter. Preferably the relax indicator 3512value is programmable by an architectural instruction, such as an MTNN1400 instruction of FIG. 14. Preferably, the architectural programrunning on the processor 100 programs the relax value into the relaxindicator 3512 just prior to instructing the NNU 121 to start runningthe NNU program, as described in more detail with respect to FIG. 37.

The weight RAM buffer 3524 is coupled between the weight RAM 124 andmedia registers 118 for buffering transfers of data between them.Preferably, the weight RAM buffer 3524 is similar to one or more of theembodiments of the buffer 1704 of FIG. 17. Preferably, the portion ofthe weight RAM buffer 3524 that receives data from the media registers118 is clocked by the primary clock signal 3506-7 at the primary clockrate and the portion of the weight RAM buffer 3524 that receives datafrom the weight RAM 124 is clocked by the secondary clock signal 3508-3at the secondary clock rate, which may or may not be reduced relative tothe primary clock rate depending upon the value programmed into therelax indicator 3512, i.e., depending upon whether the NNU 121 isoperating in relaxed or normal mode. In one embodiment, the weight RAM124 is single-ported, as described above with respect to FIG. 17, and isaccessible both by the media registers 118 via the weight RAM buffer3524 and by the NPUs 126 or the row buffer 1104 of FIG. 11 in anarbitrated fashion. In an alternate embodiment, the weight RAM 124 isdual-ported, as described above with respect to FIG. 16, and each portis accessible both by the media registers 118 via the weight RAM buffer3524 and by the NPUs 126 or the row buffer 1104 in a concurrent fashion.

Similarly, the data RAM buffer 3522 is coupled between the data RAM 122and media registers 118 for buffering transfers of data between them.Preferably, the data RAM buffer 3522 is similar to one or more of theembodiments of the buffer 1704 of FIG. 17. Preferably, the portion ofthe data RAM buffer 3522 that receives data from the media registers 118is clocked by the primary clock signal 3506-7 at the primary clock rateand the portion of the data RAM buffer 3522 that receives data from thedata RAM 122 is clocked by the secondary clock signal 3508-3 at thesecondary clock rate, which may or may not be reduced relative to theprimary clock rate depending upon the value programmed into the relaxindicator 3512, i.e., depending upon whether the NNU 121 is operating inrelaxed or normal mode. In one embodiment, the data RAM 122 issingle-ported, as described above with respect to FIG. 17, and isaccessible both by the media registers 118 via the data RAM buffer 3522and by the NPUs 126 or the row buffer 1104 of FIG. 11 in an arbitratedfashion. In an alternate embodiment, the data RAM 122 is dual-ported, asdescribed above with respect to FIG. 16, and each port is accessibleboth by the media registers 118 via the data RAM buffer 3522 and by theNPUs 126 or the row buffer 1104 in a concurrent fashion.

Preferably, the interface logic 3514 includes the data RAM buffer 3522and weight RAM buffer 3524, regardless of whether the data RAM 122and/or weight RAM 124 are single-ported or dual-ported, in order toprovide synchronization between the primary clock domain and thesecondary clock domain. Preferably, each of the data RAM 122, weight RAM124 and program memory 129 comprises a static RAM (SRAM) that includes arespective read enable, write enable and memory select signal.

As described above, the NNU 121 is an execution unit of the processor100. An execution unit is a functional unit of a processor that executesmicroinstructions into which architectural instructions are translated,such as the microinstructions 105 into which the architecturalinstructions 103 of FIG. 1 are translated, or that executesarchitectural instructions 103 themselves. An execution unit receivesoperands from general purpose registers of the processor, such as GPRs116 and media registers 118. An execution unit generates results inresponse to executing microinstructions or architectural instructionsthat may be written to the general purpose registers. Examples of thearchitectural instructions 103 are the MTNN instruction 1400 and theMFNN instruction 1500 described with respect to FIGS. 14 and 15,respectively. The microinstructions implement the architecturalinstructions. More specifically, the collective execution by theexecution unit of the one or more microinstructions into which anarchitectural instruction is translated performs the operation specifiedby the architectural instruction on inputs specified by thearchitectural instruction to produce a result defined by thearchitectural instruction.

Referring now to FIG. 36A, a timing diagram illustrating an example ofoperation of the processor 100 with the NNU 121 operating in normalmode, i.e., at the primary clock rate, is shown. Time progresses fromleft to right in the timing diagram. The processor 100 is running anarchitectural program at the primary clock rate. More specifically, theprocessor 100 front end (e.g., instruction fetch unit 101, instructioncache 102, instruction translator 104, rename unit 106, reservationstations 108) fetches, decodes and issues architectural instructions tothe NNU 121 and other execution units 112 at the primary clock rate.

Initially, the architectural program executes an architecturalinstruction (e.g., MTNN instruction 1400) that the front end 100 issuesto the NNU 121 that instructs the NNU 121 to start running an NNUprogram in its program memory 129. Prior, the architectural programexecuted an architectural instruction to write the relax indicator 3512with a value that specifies the primary clock rate, i.e., to put the NNU121 in normal mode. More specifically, the value programmed into therelax indicator 3512 causes the clock reduction logic 3504 to generatethe secondary clock signal 3508 at the primary clock rate of the primaryclock signal 3506. Preferably, in this case clock buffers of the clockreduction logic 3504 simply boost the primary clock signal 3506.Additionally prior, the architectural program executed architecturalinstructions to write to the data RAM 122 and the weight RAM 124 and towrite the NNU program into the program memory 129. In response to thestart NNU program MTNN instruction 1400, the NNU 121 starts running theNNU program at the primary clock rate, since the relax indicator 3512was programmed with the primary rate value. After starting the NNU 121running, the architectural program continues executing architecturalinstructions at the primary clock rate, including and predominately MTNNinstructions 1400 to write and/or read the data RAM 122 and weight RAM124 in preparation for the next instance, or invocation or run, of anNNU program.

As shown in the example in FIG. 36A, the NNU 121 finishes running theNNU program in significantly less time (e.g., one-fourth the time) thanthe architectural program takes to finish writing/reading the data RAM122 and weight RAM 124. For example, the NNU 121 may take approximately1000 clock cycles to run the NNU program, whereas the architecturalprogram takes approximately 4000 clock cycles to run, both at theprimary clock rate. Consequently, the NNU 121 sits idle the remainder ofthe time, which is a significantly long time in the example, e.g.,approximately 3000 primary clock rate cycles. As shown in the example inFIG. 36A, this pattern continues another time, and may continue forseveral more times, depending upon the size and configuration of theneural network. Because the NNU 121 may be a relatively large andtransistor-dense functional unit of the processor 100, it may generate asignificant amount of heat, particularly when running at the primaryclock rate.

Referring now to FIG. 36B, a timing diagram illustrating an example ofoperation of the processor 100 with the NNU 121 operating in relaxedmode, i.e., at a rate that is less than the primary clock rate, isshown. The timing diagram of FIG. 36B is similar in many respects to thetiming diagram of FIG. 36A in that the processor 100 is running anarchitectural program at the primary clock rate. And it is assumed inthe example that the architectural program and the NNU program of FIG.36B are the same as those of FIG. 36A. However, prior to starting theNNU program, the architectural program executed an MTNN instruction 1400that programmed the relax indicator 3512 with a value that causes theclock reduction logic 3504 to generate the secondary clock signal 3508at a secondary clock rate that is less than the primary clock rate. Thatis, the architectural program puts the NNU 121 in relaxed mode in FIG.36B rather than in normal mode as in FIG. 36A. Consequently, the NPUs126 execute the NNU program at the secondary clock rate, which in therelaxed mode is less than the primary clock rate. In the example, assumethe relax indicator 3512 is programmed with a value that specifies thesecondary clock rate is one-fourth the primary clock rate. As a result,the NNU 121 takes approximately four times longer to run the NNU programin relaxed mode than it does to run the NNU program in normal mode, asmay be seen by comparing FIGS. 36A and 36B, making the amount of timethe NNU 121 is idle relatively short. Consequently, the energy used torun the NNU program is consumed by the NNU 121 in FIG. 36B over a periodthat is approximately four times longer than when the NNU 121 ran theprogram in normal mode in FIG. 36A. Accordingly, the NNU 121 generatesheat to run the NNU program at approximately one-fourth the rate in FIG.36B as in FIG. 36A, which may have thermal benefits as described herein.

Referring now to FIG. 37, a flowchart illustrating operation of theprocessor 100 of FIG. 35 is shown. The flowchart illustrates operationin many respects similar to the operation described above with respectto FIGS. 35, 36A and 36B. Flow begins at block 3702.

At block 3702, the processor 100 executes MTNN instructions 1400 towrite the weight RAM 124 with weights and to write the data RAM 122 withdata. Flow proceeds to block 3704.

At block 3704, the processor 100 executes an MTNN instruction 1400 toprogram the relax indicator 3512 with a value that specifies a lowerrate than the primary clock rate, i.e., to place the NNU 121 intorelaxed mode. Flow proceeds to block 3706.

At block 3706, the processor 100 executes an MTNN instruction 1400 toinstruct the NNU 121 to start running an NNU program, similar to themanner visualized in FIG. 36B. Flow proceeds to block 3708.

At block 3708, the NNU 121 begins to run the NNU program. In parallel,the processor 100 executes MTNN instructions 1400 to write the weightRAM 124 with new weights (and potentially the data RAM 122 with newdata) and/or executes MFNN instructions 1500 to read results from thedata RAM 122 (and potentially from the weight RAM 124). Flow proceeds toblock 3712.

At block 3712, the processor 100 executes a MFNN instruction 1500 (e.g.,read the status register 127) to detect that the NNU 121 is finishedrunning its program. Assuming the architectural program selected a goodvalue of the relax indicator 3512, it should take the NNU 121 about thesame amount of time to run the NNU program as it takes the processor 100to execute the portion of the architectural program that accesses theweight RAM 124 and/or data RAM 122, as visualized in FIG. 36B. Flowproceeds to block 3714.

At block 3714, the processor 100 executes an MTNN instruction 1400 toprogram the relax indicator 3512 with a value that specifies the primaryclock rate, i.e., to place the NNU 121 into normal mode. Flow proceedsto block 3716.

At block 3716, the processor 100 executes an MTNN instruction 1400 toinstruct the NNU 121 to start running an NNU program, similar to themanner visualized in FIG. 36A. Flow proceeds to block 3718.

At block 3718, the NNU 121 begins to run the NNU program in normal mode.Flow ends at block 3718.

As described above, running the NNU program in relaxed made spreads outthe time over which the NNU runs the program relative to the time overwhich the NNU runs the program in normal mode (i.e., at the primaryclock rate of the processor), which may provide thermal benefits. Morespecifically, the devices (e.g., transistors, capacitors, wires) willlikely operate at lower temperatures while the NNU runs the program inrelaxed mode because the NNU generates at a slower rate the heat that isdissipated by the NNU (e.g., the semiconductor devices, metal layers,underlying substrate) and surrounding package and cooling solution(e.g., heat sink, fan). This may also lower the temperature of thedevices in other portions of the processor die in general. The loweroperating temperature of the devices, in particular their junctiontemperatures, may have the benefit of less leakage current. Furthermore,since the amount of current drawn per unit time is less, the inductivenoise and IR drop noise may be reduced. Still further, the lowertemperature may have a positive effect on the negative-bias temperatureinstability (NBTI) and positive-bias temperature instability (PBTI) ofMOSFETs of the processor, thereby increasing the reliability and/orlifetime of the devices and consequently the processor part. The lowertemperature may also reduce Joule heating and electromigration in metallayers of the processor.

Communication Mechanism Between Architectural Program andNon-Architectural Program Regarding Shared Resources of NNU

As described above, for example with respect to FIGS. 24 through 28 and35 through 37, the data RAM 122 and weight RAM 124 are shared resources.Both the NPUs 126 and the front-end of the processor 100 share the dataRAM 122 and weight RAM 124. More specifically, both the NPUs 126 and thefront-end of the processor 100, e.g., the media registers 118, write andread the data RAM 122 and the weight RAM 124. Stated alternatively, thearchitectural program running on the processor 100 shares the data RAM122 and weight RAM 124 with the NNU program running on the NNU 121, andin some situations this requires the control of flow between thearchitectural program and the NNU program, as described above. Thisresource sharing is also true of the program memory 129 to some extentbecause the architectural program writes it and the sequencer 128 readsit. Embodiments are described above and below that provide a highperformance solution to control the flow of access to the sharedresources between the architectural program and the NNU program.

Embodiments are described in which the NNU programs are also referred toas non-architectural programs, the NNU instructions are also referred toas non-architectural instructions, and the NNU instruction set (alsoreferred to above as the NPU instruction set) is also referred to as thenon-architectural instruction set. The non-architectural instruction setis distinct from the architectural instruction set. In embodiments inwhich the processor 100 includes an instruction translator 104 thattranslates architectural instructions into microinstructions, thenon-architectural instruction set is also distinct from themicroinstruction set.

Referring now to FIG. 38, a block diagram illustrating the sequencer 128of the NNU 121 in more detail is shown. The sequencer 128 provides thememory address 131 to the program memory 129 to select anon-architectural instruction that is provided to the sequencer 128, asdescribed above. The memory address 131 is held in a program counter3802 of the sequencer 128 as shown in FIG. 38. The sequencer 128generally increments through sequential addresses of the program memory129 unless the sequencer 128 encounters a non-architectural controlinstruction, such as a loop or branch instruction, in which case thesequencer 128 updates the program counter 3802 to the target address ofthe control instruction, i.e., to the address of the non-architecturalinstruction at the target of the control instruction. Thus, the address131 held in the program counter 3802 specifies the address in theprogram memory 129 of the non-architectural instruction of thenon-architectural program currently being fetched for execution by theNPUs 126. Advantageously, the value of the program counter 3802 may beobtained by the architectural program via the NNU program counter field3912 of the status register 127, as described below with respect to FIG.39. This enables the architectural program to make decisions about whereto read/write data from/to the data RAM 122 and/or weight RAM 124 basedon the progress of the non-architectural program.

The sequencer 128 also includes a loop counter 3804 that is used inconjunction with a non-architectural loop instruction, such as the loopto 1 instruction at address 10 of FIG. 26A and the loop to 1 instructionat address 11 of FIG. 28, for examples. In the examples of FIGS. 26A and28, the loop counter 3804 is loaded with a value specified in thenon-architectural initialize instruction at address 0, e.g., with avalue of 400. Each time the sequencer 128 encounters the loopinstruction and jumps to the target instruction (e.g., themultiply-accumulate instruction at address 1 of FIG. 26A or the maxwaccinstruction at address 1 of FIG. 28), the sequencer 128 decrements theloop counter 3804. Once the loop counter 3804 reaches zero, thesequencer 128 proceeds to the next sequential non-architecturalinstruction. In an alternate embodiment, when a loop instruction isfirst encountered, the loop counter 3804 is loaded with a loop countvalue specified in the loop instruction, obviating the need forinitialization of the loop counter 3804 via a non-architecturalinitialize instruction. Thus, the value of the loop counter 3804indicates how many more times a loop body of the non-architecturalprogram will be executed. Advantageously, the value of the loop counter3804 may be obtained by the architectural program via the loop count3914 field of the status register 127, as described below with respectto FIG. 39. This enables the architectural program to make decisionsabout where to read/write data from/to the data RAM 122 and/or weightRAM 124 based on the progress of the non-architectural program. In oneembodiment, the sequencer 128 includes three additional loop counters toaccommodate nested loops in the non-architectural program, and thevalues of the other three loop counters are also readable via the statusregister 127. A bit in the loop instruction indicates which of the fourloop counters is used for the instant loop instruction.

The sequencer 128 also includes an iteration counter 3806. The iterationcounter 3806 is used in conjunction with non-architectural instructionssuch as the multiply-accumulate instruction at address 2 of FIGS. 4, 9,20 and 26A, and the maxwacc instruction at address 2 of FIG. 28, forexamples, which will be referred to hereafter as “execute” instructions.In the examples above, each of the execute instructions specifies aniteration count of 511, 511, 1023, 2, and 3, respectively. When thesequencer 128 encounters an execute instruction that specifies anon-zero iteration count, the sequencer 128 loads the iteration counter3806 with the specified value. Additionally, the sequencer 128 generatesan appropriate micro-operation 3418 to control the logic in the NPU 126pipeline stages 3401 of FIG. 34 for execution and decrements theiteration counter 3806. If the iteration counter 3806 is greater thanzero, the sequencer 128 again generates an appropriate micro-operation3418 to control the logic in the NPUs 126 and decrements the iterationcounter 3806. The sequencer 128 continues in this fashion until theiteration counter 3806 reaches zero. Thus, the value of the iterationcounter 3806 indicates how many more times the operation specified inthe non-architectural execute instruction (e.g., multiply-accumulate,maximum, sum of the accumulator and a data/weight word) will beperformed. Advantageously, the value of the iteration counter 3806 maybe obtained by the architectural program via the iteration count 3916field of the status register 127, as described below with respect toFIG. 39. This enables the architectural program to make decisions aboutwhere to read/write data from/to the data RAM 122 and/or weight RAM 124based on the progress of the non-architectural program.

Referring now to FIG. 39, a block diagram illustrating certain fields ofthe control and status register 127 of the NNU 121 is shown. The fieldsinclude the address of the most recently written weight RAM row 2602 bythe NPUs 126 executing the non-architectural program, the address of themost recently read weight RAM row 2604 by the NPUs 126 executing thenon-architectural program, the address of the most recently written dataRAM row 2606 by the NPUs 126 executing the non-architectural program,and the address of the most recently read data RAM row 2604 by the NPUs126 executing the non-architectural program, which are described abovewith respect to FIG. 26B. Additionally, the fields include an NNUprogram counter 3912, a loop count 3914 and an iteration count 3916. Asdescribed above, the status register 127 is readable by thearchitectural program into the media registers 118 and/or generalpurpose registers 116, e.g., by MFNN instructions 1500, including theNNU program counter 3912, loop count 3914 and iteration count 3916 fieldvalues. The program counter 3912 value reflects the value of the programcounter 3802 of FIG. 38. The loop count 3914 value reflects the value ofthe loop counter 3804. The iteration count 3916 value reflects the valueof the iteration counter 3806. In one embodiment, the sequencer 128updates the program counter 3912, loop count 3914 and iteration count3916 field values each time it modifies the program counter 3802, loopcounter 3804, or iteration counter 3806 so that the field values arecurrent when the architectural program reads them. In anotherembodiment, when the NNU 121 executes an architectural instruction thatreads the status register 127, the NNU 121 simply obtains the programcounter 3802, loop counter 3804, and iteration counter 3806 values andprovides them back to the architectural instruction (e.g., into a mediaregister 118 or general purpose register 116).

As may be observed from the forgoing, the values of the fields of thestatus register 127 of FIG. 39 may be characterized as information thatindicates progress made by the non-architectural program during itsexecution by the NNU 121. Specific aspects of the non-architecturalprogram's progress have been described above, such as the programcounter 3802 value, the loop counter 3804 value, the iteration counter3806 value, the weight RAM 124 address 125 most recently written/read2602/2604, and the data RAM 122 address 123 most recently written/read2606/2608. The architectural program executing on the processor 100 mayread the non-architectural program progress values of FIG. 39 from thestatus register 127 and use the information to make decisions, e.g., byarchitectural instructions, such as compare and branch instructions. Forexample, the architectural program decides which rows to write/readdata/weights into/from the data RAM 122 and/or weight RAM 124 to controlthe flow of data in and out of the data RAM 122 or weight RAM 124,particularly for large data sets and/or for overlapping executioninstances of different non-architectural programs. Examples of thedecisions made by the architectural program are described above andbelow.

For example, as described above with respect to FIG. 26A, thearchitectural program configures the non-architectural program to writeback the results of the convolutions to rows of the data RAM 122 abovethe convolution kernel 2402 (e.g., above row 8), and the architecturalprogram reads the results from the data RAM 122 as the NNU 121 writesthem by using the address of the most recently written data RAM 122 row2606.

For another example, as described above with respect to FIG. 26B, thearchitectural program uses the information from the status register 127fields of FIG. 38 to determine the progress of a non-architecturalprogram to perform a convolution of the data array 2404 of FIG. 24 in 5chunks of 512×1600. The architectural program writes a first 512×1600chunk of the 2560×1600 data array 2404 into the weight RAM 124 andstarts the non-architectural program, which has a loop count of 1600 andan initialized weight RAM 124 output row of 0. As the NNU 121 executesthe non-architectural program, the architectural program reads thestatus register 127 to determine the most recently written weight RAMrow 2602 so that it may read the valid convolution results written bythe non-architectural program and write the next 512×1600 chunk over thevalid convolution results after the architectural program has read them,so that when the NNU 121 completes the non-architectural program on thefirst 512×1600 chunk, the processor 100 can immediately update thenon-architectural program as needed and start it again to process thenext 512×1600 chunk.

For another example, assume the architectural program is having the NNU121 perform a series of classic neural networkmultiply-accumulate-activation function operations in which the weightsare stored in the weight RAM 124 and the results are written back to thedata RAM 122. In this case, once the non-architectural program has reada row of the weight RAM 124 it will not be reading it again. So, thearchitectural program may be configured to begin overwriting the weightsin the weight RAM 124 with new weights for a next execution instance ofa non-architectural program (e.g., for a next neural network layer) oncethe current weights have been read/used by the non-architecturalprogram. In this case, the architectural program reads the statusregister 127 to obtain the address of the most recently read weight ramrow 2604 to decide where it may write the new set of weights into theweight RAM 124.

For another example, assume the architectural program knows that thenon-architectural program includes an execute instruction with a largeiteration count, such as the non-architectural multiply-accumulateinstruction at address 2 of FIG. 20. In such cases, the architecturalprogram may need to know the iteration count 3916 in order to knowapproximately how many more clock cycles it will take to complete thenon-architectural instruction so that the architectural program candecide which of two or more actions to take. For example, thearchitectural program may relinquish control to another architecturalprogram, such as the operating system, if the time is long. Similarly,assume the architectural program knows that the non-architecturalprogram includes a loop body with a relatively large loop count, such asthe non-architectural program of FIG. 28. In such cases, thearchitectural program may need to know the loop count 3914 in order toknow approximately how many more clock cycles it will take to completethe non-architectural program so that the architectural program candecide which of two or more actions to take.

For another example, assume the architectural program is having the NNU121 perform a pooling operation similar to that described with respectto FIGS. 27 and 28 in which the data to be pooled is stored in theweight RAM 124 and the results are written back to the weight RAM 124.However, assume that, unlike the example of FIGS. 27 and 28, the resultsare written back to the top 400 rows of the weight RAM 124, e.g., rows1600 to 1999. In this case, once the non-architectural program has readfour rows of the weight RAM 124 that it pools, it will not be reading itagain. So, the architectural program may be configured to beginoverwriting the data in the weight RAM 124 with new data (e.g., weightsfor a next execution instance of a non-architectural program, e.g., toperform classic multiply-accumulate-activation function operations onthe pooled data) once the current four rows have been read/used by thenon-architectural program. In this case, the architectural program readsthe status register 127 to obtain the address of the most recently readweight ram row 2604 to decide where it may write the new set of weightsinto the weight RAM 124.

The examples described above may also be performed by embodimentsdescribed with respect to FIGS. 41 through 46 below in which the NNU 121is coupled to processing cores by a ring bus, rather than being anexecution unit of a processing core, and to which ring bus a systemmemory is also coupled. In such embodiments, because the transfer ofdata/weights between the NNU 121 (e.g., data RAM 122 and weight RAM 124)and the core and/or the system memory may incur longer latencies than inembodiments in which the NNU 121 is an execution unit of a core, it maybe particularly beneficial to enable the architectural program to makedecisions about where to read/write data from/to the data RAM 122 and/orweight RAM 124 based on the progress of the non-architectural program.Furthermore, it may be beneficial for the NNU 121 to be capable ofinterrupting the core in a very fine-tuned manner in order to navigatethe interrupt latency associated with the core and its operating system,embodiments of which are described below with respect to FIGS. 47through 53.

Referring now to FIG. 40, a block diagram illustrating an embodiment ofportions of the NNU 121 is shown. The NNU 121 includes a move unit 5802,a move register 5804, a data mux-reg 208, a weight mux-reg 705, an NPU126, a multiplexer 5806, out units 5808 and an out register 1104. Thedata mux-reg 208 and weight mux-reg 705 are similar to those describedabove, but modified to additionally receive an input from the moveregister 5804 and from additional adjacent NPUs 126. In one embodiment,the data mux-reg 208 also receives on inputs 211 the output 209 fromNPUs J−1 and J−4 in addition to output 209 from J+1 as described above;similarly, the weight mux-reg 705 also receives on inputs 711 the output203 from NPUs J−1 and J−4 in addition to output 203 from J+1 asdescribed above. The out register 1104 is similar to that describedabove where referred to as the row buffer 1104 and output buffer 1104.The out units 5808 are similar in many respects to the activationfunction units 212/1112 described above in that they may includeactivation functions (e.g., sigmoid, tanh, rectify, softplus); however,preferably the out units 5808 also include a re-quantization unit thatre-quantizes the accumulator 202 values, embodiments of which aredescribed below. The NPU 126 is similar in many respects to thosedescribed above. As described above, different embodiments arecontemplated in which the data and weight word widths may be varioussizes (e.g., 8-bit, 9-bit, 12-bit or 16-bit) and multiple word sizes maybe supported by a given embodiment (e.g., 8-bit and 16-bit). However,representative embodiments are shown with respect to the followingFigures in which the data and weight word widths held in the memories122/124, move register 5804, mux-regs 208/705 and out register 1104 are8-bit words, i.e., bytes.

FIG. 40 illustrates a cross-section of the NNU 121. For example, the NPU126 shown is representative of the array of NPUs 126, such as thosedescribed above. The representative NPU 126 is referred to as NPU[J] 126of N NPUs 126, where J is between 0 and N-1. As described above, N is alarge number, and preferably a power of two. As described above, N maybe 512, 1024 or 2048. In one embodiment, N is 4096. Due to the largenumber of NPUs 126 in the array, it is advantageous that each NPU 126 isas small as possible to keep the size of the NNU 121 within desirablelimits and/or to accommodate more NPUs 126 to increase the accelerationof neural network-related computations by the NNU 121.

Furthermore, although the move unit 5802 and the move register 5804 areeach N bytes wide, only a portion of the move register 5804 is shown.Specifically, the portion of the move register 5804 whose output 5824provides a byte to the mux-regs 208/705 of NPU[J] 126 is shown, which isdenoted move reg[J] 5804. Furthermore, although the output 5822 of themove unit 5802 provides N bytes (to the memories 122/124 and to the moveregister 5804), only byte J is provided for loading into move reg[J]5804, which move reg[J] 5804 subsequently provides on its output 5824 tothe data mux-reg 208 and to the weight mux-reg 705.

Still further, although the NNU 121 includes a plurality of out units5808, only a single out unit 5808 is shown in FIG. 40, namely the outunit 5808 that operates on the accumulator output 217 of NPU[J] 126 andthe NPUs 126 within its NPU group, such as described above with respectto FIG. 11 and with respect to FIG. 52 of U.S. patent application Ser.Nos. 15,090,701, 15,090,705, 15,090,801, 15,090,807, 15,090,814, and15,090,829, which are referred to herein as “The Earlier Applications”and which are published as U.S. Patent Application Publication Nos.20170103040, 20170103041, 20170102941, 20170103305, 20170103303,20170103312, each of which is hereby incorporated by reference herein inits entirety for all purposes. The out unit 5808 is referred to as outunit[J/4] because each out unit 5808 is shared by a group of four NPUs126 in the embodiment of FIG. 40, similar to the embodiment of FIG. 52of The Earlier applications. Similarly, although the NNU 121 includes aplurality of multiplexers 5806, only a single multiplexer 5806 is shownin FIG. 40, namely the multiplexer 5806 that receives the accumulatoroutput 217 of NPU[J] 126 and the NPUs 126 within its NPU group.Similarly, the multiplexer 5806 is referred to as multiplexer[J/4]because it selects one of the four accumulator 202 outputs 217 forprovision to out unit[J/4] 5808.

Finally, although the out register 1104 is N bytes wide, only a single4-byte section is shown in FIG. 40, denoted out register[J/4] 1104,which receives the four quantized bytes generated by out unit[J/4] 5808from the four NPUs 126 of the NPU group that includes NPU[J] 126. All Nbytes of the output 133 of the out register 1104 are provided to themove unit 5802, although only the four bytes of the four-byte section ofout register[J/4] 1104 are shown in FIG. 40. Additionally, the fourbytes of the four-byte section of out register[J/4] 1104 are provided asinputs to the mux-regs 208/705 as described in more detail with respectto FIGS. 49 and 52 of The Earlier applications.

Although the mux-regs 208/705 are shown in FIG. 40 as distinct from theNPU 126, there is a pair of respective mux-regs 208/705 associated witheach NPU 126, and the mux-regs 208/705 may be considered part of the NPU126, as described above with respect to FIGS. 2 and 7 and FIGS. 49 and52 of The Earlier applications, for example.

The output 5822 of the move unit 5802 is coupled to the move register5804, the data RAM 122 and the weight RAM 124, to each of which theoutput 5822 may be written. The move unit 5802 output 5822, the moveregister 5804, the data RAM 122 and the weight RAM 124 are all N byteswide (e.g., N is 4096). The move unit 5802 receives N quantized bytesfrom five different sources and selects one of them as its input: thedata RAM 122, the weight RAM 124, the move register 5804, the outregister 1104, and an immediate value. Preferably, the move unit 5802comprises many multiplexers that are interconnected to be able toperform operations on its input to generate its output 5822, whichoperations which will now be described.

The operations the move unit 5802 performs on its inputs include:passing the input through to the output; rotating the input by aspecified amount; and extracting and packing specified bytes of theinput. The operation is specified in a MOVE instruction fetched from theprogram memory 129. In one embodiment, the rotate amounts that may bespecified are 8, 16, 32 and 64 bytes. In one embodiment, the rotatedirection is left, although other embodiments are contemplated in whichthe rotate direction is right, or either direction. In one embodiment,the extract and pack operation is performed within blocks of the inputof a predetermined size. The block size is specified by the MOVEinstruction. In one embodiment, the predetermined block sizes are 16, 32and 64 bytes, and blocks are located on aligned boundaries of thespecified block size. Thus, for example when the MOVE instructionspecifies a block size of 32, the move unit 5802 extracts the specifiedbytes within each 32-byte block of the N bytes of the input (e.g., if Nis 4096, then there are 128 blocks) and packs them within the respective32-byte block (preferably at one end of the block). In one embodiment,the NNU 121 also includes an N-bit mask register (not shown) associatedwith the move register 5804. A MOVE instruction specifying a load maskregister operation may specify as its source a row of the data RAM 122or the weight RAM 124. In response to the MOVE instruction specifying aload mask register operation, the move unit 5802 extracts bit 0 fromeach of the N words of the RAM row and stores the N bits into itsrespective bit of the N-bit mask register. The bits of the bit maskserve as a write enable/disable for respective bytes of the moveregister 5804 during execution of a subsequent MOVE instruction thatwrites to the move register 5804. In an alternate embodiment, a 64-bitmask is specified by an INITIALIZE instruction for loading into a maskregister prior to execution of a MOVE instruction that specifies anextract and pack function; in response to the MOVE instruction, the moveunit 5802 extracts the bytes within each block (of the 128 blocks, forexample) that are specified by the 64-bit mask stored in the maskregister. In an alternate embodiment, a MOVE instruction that specifiesan extract and pack operation also specifies a stride and an offset; inresponse to the MOVE instruction, the move unit 5802 extracts every Nthbyte within each block starting at the byte specified by the offset,where N is the stride, and compresses the extracted bytes together. Forexample, if the MOVE instruction specifies a stride of 3 and an offsetof 2, then the move unit 5802 extracts every third by starting at byte 2within each block.

Ring Bus-Connected Neural Network Unit

Embodiments have been described above in which the NNU 121 is anexecution unit of a processor 100. Embodiments will now be described inwhich the NNU 121 resides on a ring bus along with more conventionalprocessing cores of a multi-core processor to operate as a neuralnetwork accelerator shared by the other cores to perform neuralnetwork-related computations on behalf of the cores in a moreexpeditious manner than the cores can perform them. In many respects,the NNU 121 operates like a peripheral device in that programs runningon the cores may control the NNU 121 to perform the neuralnetwork-related computations. Preferably, the multi-core processor andNNU 121 are fabricated on a single integrated circuit. Because the sizeof the NNU 121 may be significantly large, particularly for embodimentsin which the number of NPUs 126 and size of the memories 122/124 islarge (e.g., 4096 NPUs 126 with 4096 byte-wide data RAM 122 and weightRAM 124), such an embodiment may provide the advantage that it does notincrease the size of each core by the size of the NNU 121, but insteadthere are fewer NNUs 121 than cores and the cores share the NNU 121,which enables the integrated circuit to be smaller, albeit in exchangefor potentially less performance.

Referring now to FIG. 41, a block diagram illustrating a processor 100is shown. The processor 100 includes a plurality of ring stops 4004connected to one another in a bidirectional fashion to form a ring bus4024. The embodiment of FIG. 41 includes seven ring stops denoted4004-0, 4004-1, 4004-2, 4004-3, 4004-M, 4004-D and 4004-U. The processor100 includes four core complexes 4012, referred to individually as corecomplex 0 4012-0, core complex 1 4012-1, core complex 2 4012-2 and corecomplex 3 4012-3, which include the four ring stops 4004-0, 4004-1,4004-2 and 4004-3 respectively, that couple the core complexes 4012 tothe ring bus 4024. The processor 100 also includes an uncore portion4016, which includes the ring stop 4004-U that couples the uncore 4016to the ring bus 4024. Finally, the processor 100 includes a dynamicrandom access memory (DRAM) controller 4018 that is coupled to the ringbus 4024 by the ring stop 4004-D. Finally, the processor 100 includes aNNU 121 that is coupled to the ring bus 4024 by the ring stop 4004-M. Inone embodiment, described in U.S. Non-Provisional application Nos.15366027, 15366053 and 15366057, hereinafter referred to as the “DualUse NNU Memory Array Applications,” each filed on Dec. 1, 2016, and eachof which is hereby incorporated by reference herein in its entirety, theNNU 121 includes a memory array that may be employed as either a memoryused by the array of NPUs 126 of the NNU 121 (e.g., weight RAM 124 ofFIG. 1) or as a cache memory shared by the core complexes 4012, e.g., asa victim cache or as a slice of a last-level cache (LLC), as describedtherein. Although the example of FIG. 41 includes four core complexes4012, other embodiments are contemplated with different numbers of corecomplexes 4012. For example, in one embodiment the processor 100includes eight core complexes 4012.

The uncore 4016 includes a bus controller 4014 that controls access bythe processor 100 to a system bus 4022 to which peripheral devices maybe coupled, for example, such as video controllers, disk controllers,peripheral bus controllers (e.g., PCI-E), etc. In one embodiment, thesystem bus 4022 is the well-known V4 bus. The uncore 4016 may alsoinclude other functional units, such as a power management unit andprivate RAM (e.g., non-architectural memory used by microcode of thecores 4002). In an alternate embodiment, the DRAM controller 4018 iscoupled to the system bus, and the NNU 121 accesses system memory viathe ring bus 4024, bus controller 4014 and DRAM controller 4018.

The DRAM controller 4018 controls DRAM (e.g., asynchronous DRAM orsynchronous DRAM (SDRAM) such as double data rate synchronous DRAM,direct Rambus DRAM or reduced latency DRAM) that is the system memory.The core complexes 4012, uncore 4016 and NNU 121 access the systemmemory via the ring bus 4024. More specifically, the NNU 121 readsneural network weights and data from the system memory into the data RAM122 and weight RAM 124 and writes neural network results from the dataRAM 122 and weight RAM 124 to the system memory via the ring bus 4024.Additionally, when operating as a victim cache, the memory array (e.g.,data RAM 122 or weight RAM 124), under the control of cache controllogic, evicts cache lines to the system memory. Furthermore, whenoperating as a LLC slice, the memory array and cache control logic fillcache lines from the system memory and write back and evict cache linesto the system memory.

The four core complexes 4012 include respective LLC slices 4012-0,4012-1, 4012-2 and 4012-3, each of which is coupled to the ring stop4004, and which are referred to individually generically as LLC slice4006 and collectively as LLC slices 4006. Each core 4002 includes acache memory, such as a level-2 (L2) cache 4008 coupled to the ring stop4004. Each core 4002 may also include a level-1 cache (not shown). Inone embodiment, the cores 4002 are x86 instruction set architecture(ISA) cores, although other embodiments are contemplated in which thecores 4002 are of another ISA, e.g., ARM, SPARC, MIPS.

The LLC slices 4006-0, 4006-1, 4006-2 and 4006-3 collectively form a LLC4005 of the processor 100 shared by the core complexes 4012, as shown inFIG. 41. Each LLC slice 4006 includes a memory array and cache controllogic. A mode indicator may be set such that the memory array of the NNU121 operates as an additional (e.g., fifth or ninth) slice 4006-4 of theLLC 4005, as described in the Dual Use NNU Memory Array Applicationsincorporated by reference above. In one embodiment, each LLC slice 4006comprises a 2 MB memory array, although other embodiments arecontemplated with different sizes. Furthermore, embodiments arecontemplated in which the sizes of the memory array and the LLC slices4006 are different. Preferably, the LLC 4005 is inclusive of the L2caches 4008 and any other caches in the cache hierarchy (e.g., L1caches).

The ring bus 4024, or ring 4024, is a scalable bidirectionalinterconnect that facilitates communication between coherent componentsincluding the DRAM controller 4018, the uncore 4016, and the LLC slices4006. The ring 4024 comprises two unidirectional rings, each of whichfurther comprises five sub-rings: Request, for transporting most typesof request packets including loads; Snoop, for transporting snooprequest packets; Acknowledge, for transporting response packets; Data,for transporting data packets and certain request items includingwrites; and Credit, for emitting and obtaining credits in remote queues.Each node attached to the ring 4024 is connected via a ring stop 4004,which contains queues for sending and receiving packets on the ring4024, e.g., as described in more detail with respect to FIGS. 42 through44. Queues are either egress queues that initiate requests on the ring4024 on behalf of an attached component to be received in a remotequeue, or ingress queues that receive requests from the ring 4024 to beforwarded to an attached component. Before an egress queue initiates arequest on the ring, it first obtains a credit on the Credit ring fromthe remote destination ingress queue. This ensures that the remoteingress queue has resources available to process the request upon itsarrival. When an egress queue wishes to send a transaction packet on thering 4024, it can only do so if it would not preempt an incoming packetultimately destined to a remote node. When an incoming packet arrives ina ring stop 4004 from either direction, the packet's destination ID isinterrogated to determine if this ring stop 4004 is the packet'sultimate destination. If the destination ID is not equal to the ringstop's 4004 node ID, the packet continues to the next ring stop 4004 inthe subsequent clock. Otherwise, the packet leaves the ring 4024 in thesame clock to be consumed by whichever ingress queue is implicated bythe packet's transaction type.

Generally, the LLC 4005 comprises N LLC slices 4006, where each of the Nslices 4006 is responsible for caching a distinct approximately 1/Nth ofthe processor's 100 physical address space determined by a hashingalgorithm, or hash algorithm, or simply hash. The hash is a functionthat takes as input a physical address and selects the appropriate LLCslice responsible for caching the physical address. When a request mustbe made to the LLC 4005, either from a core 4002 or snooping agent, therequest must be sent to the appropriate LLC slice 4006 that itresponsible for caching the physical address of the request. Theappropriate LLC slice 4006 is determined by applying the hash to thephysical address of the request.

A hash algorithm is a subjective function whose domain is the set ofphysical addresses, or a subset thereof, and whose range is the numberof currently included LLC slices 4006. More specifically, the range isthe set of indexes of the LLC slices 4006, e.g., 0 through 7 in the caseof eight LLC slices 4006. The function may be computed by examining anappropriate subset of the physical address bits. For example, in asystem with eight LLC slices 4006, the output of the hashing algorithmmay be simply PA[10:8], which is three of the physical address bits,namely bits 8 through 10. In another embodiment in which the number ofLLC slices 4006 is eight, the output of the hash is a logical functionof other address bits, e.g., three bits generated as {PA[17], PA[14],PA[12]̂PA[10]̂PA[9]}.

All requestors of the LLC 4005 must have the same hash algorithm beforeany LLC 4005 caching is done. Because the hash dictates where addressesare cached and where snoops will be sent during operation, the hash isonly changed through coordination between all cores 4002, LLC slices4006, and snooping agents. As described in the Dual Use NNU Memory ArrayApplications, updating the hash algorithm essentially comprises: (1)synchronizing all cores 4002 to prevent new cacheable accesses; (2)performing a write-back-invalidate of all LLC slices 4006 currentlyincluded in the LLC 4005, which causes modified cache lines to bewritten back to system memory and all cache lines to be invalidated (thewrite-back-invalidate may be a selective write-back-invalidate,described below, in which only those cache lines whose addresses the newhash algorithm will hash to a different slice than the old hashalgorithm are evicted, i.e., invalidated and, if modified, written backbefore being invalidated); (3) broadcasting a hash update message toeach core 4002 and snoop source, which commands them to change to a newhash (either from inclusive hash to exclusive hash, or vice versa, asdescribed below); (4) updating the mode input to selection logic thatcontrols access to the memory array; and (5) resuming execution with thenew hash algorithm.

The hash algorithms described above are useful when the number of LLCslices 4006, N, is 8, which is a power of 2, and those algorithms may bemodified to easily accommodate other powers of 2, e.g., PA[9:8] for 4slices or PA[11:8] for 16 slices. However, depending upon whether theNNU LLC slice 4006-4 is included in the LLC 4005 (and the number of corecomplexes 4012), N may or may not be a power of 2. Therefore, asdescribed in the Dual Use NNU Memory Array Applications, at least twodifferent hashes may be used when the NNU 121 memory array has a dualuse.

In an alternate embodiment, the NNU 121 and DRAM controller 4018 areboth coupled to a single ring stop 4004. The single ring stop 4004includes an interface that enables the NNU 121 and DRAM controller 4018to transfer requests and data between each other rather than doing soover the ring bus 4024. This may be advantageous because it may reducetraffic on the ring bus 4024 and provide increased performance oftransfers between the NNU 121 and system memory.

Preferably, the processor 100 is fabricated on a single integratedcircuit, or chip. Thus, data transfers may be accomplished between thesystem memory and/or LLC 4005 and the NNU 121 at a very high sustainablerate, which may be very advantageous for neural network applications,particularly in which the amount of weights and/or data is relativelylarge. That is, the NNU 121, although not an execution unit of a core4002 as in the embodiment of FIG. 1, is tightly coupled to the cores4002, which may provide a significant memory performance advantage over,for example, a neural network unit that couples to a peripheral bus,such as a PCIe bus.

Referring now to FIG. 42, a block diagram illustrating the ring stop4004-N of FIG. 41 in more detail is shown. The ring stop 4004-N includesa slave interface 6301, a first master interface referred to as masterinterface 0 6302-0, and a second master interface referred to as masterinterface 1 6302-1. Master interface 0 6302-0 and master interface 16302-1 are referred to generically individually as master interface 6302and collectively as master interfaces 6302. The ring stop 4004-N alsoincludes three arbiters 6362, 6364 and 6366 coupled to respectivebuffers 6352, 6354 and 6356 that respectively provide an outgoingrequest (REQ), data (DATA) and acknowledgement (ACK) on a firstunidirectional ring 4024-0 of the ring bus 4024; the three arbiters6362, 6364 and 6366 respectively receive an incoming request (REQ), data(DATA) and acknowledgement (ACK) on the first unidirectional ring4024-0. The ring stop 4004-N includes an additional three arbiters 6342,6344 and 6346 coupled to additional respective buffers 6332, 6334 and6336 that respectively provide an outgoing request (REQ), data (DATA)and acknowledgement (ACK) on the second unidirectional ring 4024-1 ofthe ring bus 4024; the three arbiters 6342, 6344 and 6346 respectivelyreceive an incoming request (REQ), data (DATA) and acknowledgement (ACK)on the second unidirectional ring 4024-1. The Request, Data andAcknowledgement subrings of each unidirectional ring of the ring bus4024 are described above. The Snoop and Credit sub-rings are not shown,although the slave interface 6301 and master interfaces 6302 are alsocoupled to the Snoop and Credit sub-rings.

The slave interface 6301 includes a load queue 6312 and a store queue6314; the master interface 0 6302-0 includes a load queue 6322 and astore queue 6324; and the master interface 1 6302-1 includes a loadqueue 6332 and a store queue 6334. The slave interface 6301 load queue6312 receives and queues requests from both unidirectional rings 4024-0and 4024-1 of the ring bus 4024 and provides queued data to each of therespective arbiters 6364 and 6344 of the ring bus 4024. The slaveinterface 6301 store queue 6314 receives and queues data from bothdirections of the ring bus 4024 and provides acknowledgements to each ofthe respective arbiters 6366 and 6346 of the ring bus 4024. The masterinterface 0 6302-0 load queue 6322 receives data from the secondunidirectional ring 4024-1 and provides queued requests to arbiter 6362of the first unidirectional ring 4024-0. The master interface 0 6302-0store queue 6324 receives acknowledgements from the secondunidirectional ring 4024-1 and provides queued data to arbiter 6364 ofthe first unidirectional ring 4024-0. The master interface 1 6302-1 loadqueue 6332 receives data from the first unidirectional ring 4024-0 andprovides queued requests to arbiter 6342 of the second unidirectionalring 4024-1. The master interface 1 6302-1 store queue 6334 receivesacknowledgements from the first unidirectional ring 4024-0 and providesqueued data to arbiter 6344 of the second unidirectional ring 4024-1.The slave interface 6301 load queue 6312 provides queued requests to theNNU 121 and receives data from the NNU 121. The slave interface 6301store queue 6314 provides queued requests and data to the NNU 121 andreceives acknowledgements from the NNU 121. The first master interface 06302-0 load queue 6322 receives and queues requests from the NNU 121 andprovides data to the NNU 121. The first master interface 0 6302-0 storequeue 6324 receives and queues requests and data from the NNU 121 andprovides acknowledgements to the NNU 121. The second master interface 16302-1 load queue 6332 receives and queues requests from the NNU 121 andprovides data to the NNU 121. The second master interface 1 6302-2 storequeue 6334 receives and queues requests and data from the NNU 121 andprovides acknowledgements to the NNU 121.

Typically, the slave interface 6301 receives requests made by a core4002 to load data from the NNU 121 (which are received by the load queue6312) and receives requests made by a core 4002 to store data to the NNU121 (which are received by the store queue 6314), although the slaveinterface 6301 may also receive such requests from other ring bus 4024agents. For example, via the slave interface 6301, the core 4002 maywrite control data to and read status data from the control/statusregisters 127; write instructions to the program memory 129; write/readdata/weights to/from the data RAM 122 and weight RAM 124; and writecontrol words to the bus controller memory 6636 to program the DMAcontrollers 6602 (see FIG. 45) of the NNU 121. More specifically, inembodiments in which the NNU 121 resides on the ring bus 4024 ratherthan as a core 4002 execution unit, the core 4002 may write to thecontrol/status registers 127 to instruct the NNU 121 to performoperations similar to those described with respect to the MTNNinstructions 1400 of FIG. 14 and may read from the control/statusregisters 127 to instruct the NNU 121 to perform operations similar tothose described with respect to the MFNN instructions 1500 of FIG. 15.The list of operations includes, but is not limited to, startingexecution of a program in the program memory 129, pausing the executionof a program in the program memory 129, requesting notification (e.g.,interrupt) of completion of the execution of a program in the programmemory 129, resetting the NNU 121, writing to DMA base registers, andwriting to a strobe address to cause a row buffer to be written to orread from the data/weight RAM 122/124. Additionally, the slave interface6301 may generate an interrupt (e.g., a PCI interrupt) to each of thecores 4002 at the request of the NNU 121. Preferably, the sequencer 128instructs the slave interface 6301 to generate the interrupt, e.g., inresponse to decoding an instruction fetched from the program memory 129.Alternatively, the DMACs 6602 may instruct the slave interface 6301 togenerate the interrupt, e.g., in response to completing a DMA operation(e.g., after writing data words that are the result of a neural networklayer computation from the data RAM 122 to system memory). In oneembodiment, the interrupt includes a vector, such as an 8-bit x86interrupt vector. Preferably, a flag in a control word read by a DMAC6602 from the bus control memory 6636 specifies whether or not the DMAC6602 is to instruct the slave interface 6301 to generate an interrupt atcompletion of a DMA operation.

Typically, the NNU 121 generates requests via the master interfaces 6302(which are received by the store queues 6324/6334) to write data tosystem memory and generates requests via the master interfaces 6302(which are received by the load queues 6322/6332) to read data fromsystem memory (e.g., via the DRAM controller 4018), although the masterinterfaces 6302 may also receive requests from the NNU 121 to write/readdata to/from other ring bus 4024 agents. For example, via the masterinterfaces 6302, the NNU 121 may transfer data/weights from systemmemory to the data RAM 122 and weight RAM 124, and may transfer data tosystem memory from the data RAM 122 and weight RAM 124.

Preferably, the various entities of the NNU 121 that are accessible viathe ring bus 4024, such as the data RAM 122, weight RAM 124, programmemory 129, bus control memory 6636, and control/status registers 127,are memory-mapped within the system memory space. In one embodiment, theaccessible NNU 121 entities are memory mapped via PCI configurationregisters of the well-known Peripheral Component Interconnect (PCI)configuration protocol.

An advantage of having two master interfaces 6302 to the ring stop4004-N is that it enables the NNU 121 to concurrently transmit to and/orreceive from both system memory (via the DRAM controller 4018) and thevarious L3 slices 4006, or alternatively to concurrently transmit toand/or receive from the system memory at twice the bandwidth of anembodiment that has a single master interface.

In one embodiment, the data RAM 122 is 64 KB arranged as 16 rows of 4 KBeach and therefore requires four bits to specify its row address; theweight RAM 124 is 8 MB arranged as 2K rows of 4 KB each and thereforerequires eleven bits to specify its row address; the program memory 129is 8 KB arranged as 1K rows of 64 bits each and therefore requires 10bits to specify its row address; the bus control memory 6636 is 1 KBarranged as 128 rows of 64 bits each and therefore requires 7 bits tospecify its row address; each of the queues6312/6314/6322/6324/6332/6334 includes 16 entries and therefore requiresfour bits to specifies the index of an entry. Additionally, the Datasub-ring of a unidirectional ring 4024 of the ring bus 4024 is 64 byteswide. A quantum of 64 bytes will therefore be referred to herein as ablock, data block, block of data, etc. (“data” may be used genericallyto refer to both data and weights). Thus, a row of the data RAM 122 orweight RAM 124, although not addressable at a block level, is subdividedinto 64 blocks each; furthermore, each of the data/weight write buffers6612/6622 (of FIG. 45) and data/weight read buffers 6614/6624 (of FIG.45) is also subdivided into 64 blocks of 64 bytes each and isaddressable at a block level; therefore, six bits are required tospecify an address of a block within a row/buffer. The followingdescriptions assume these sizes for ease of illustration; however, otherembodiments are contemplated in which the various sizes are different.

Referring now to FIG. 43, a block diagram illustrating in more detailthe slave interface 6301 of FIG. 42 is shown. The slave interface 6301includes the load queue 6312 and store queue 6314 and arbiters 6342,6344, 6346, 6362, 6364 and 6366 and buffers 6332, 6334, 6336, 6352, 6354and 6356 coupled to the ring bus 4024 of FIG. 42. FIG. 43 also includesother requestors 6472 (e.g., master interface 0 6302-0) that generaterequests to arbiter 6362 and other requestors 6474 (e.g., masterinterface 1 6302-1) that generate requests to arbiter 6342.

The slave load queue 6312 includes a queue of entries 6412 coupled to arequest arbiter 6416 and a data arbiter 6414. In the embodiment shown,the queue includes 16 entries 6412. Each entry 6412 includes storage foran address, a source identifier, a direction, a transaction identifier,and a block of data associated with the request. The address specifiesthe location within the NNU 121 from which the requested data is to beloaded for returning to the requesting ring bus 4024 agent (e.g., a core4002). The address may specify a control/status register 127 or a blocklocation within the data RAM 122 or weight RAM 124. When the addressspecifies a block location within the data/weight RAM 122/124, the upperbits specify a row of the data/weight RAM 122/124, and the lower bits(e.g., 6 bits) specify a block within the specified row. Preferably, thelower bits are used to control the data/weight read buffer multiplexer6615/6625 (see FIG. 45) to select the appropriate block within thedata/weight read buffer 6614/6624 (see FIG. 45). The source identifierspecifies the requesting ring bus 4024 agent. The direction specifieswhich of the two unidirectional rings 4024-0 or 4024-1 upon which thedata is to be sent back to the requesting agent. The transactionidentifier is specified by the requesting agent and is returned by thering stop 4004-N to the requesting agent along with the requested data.

Each entry 6412 also has an associated state. A finite state machine(FSM) updates the state. In one embodiment, the FSM operates as follows.When the load queue 6312 detects a load request on the ring bus 4024destined for itself, the load queue 6312 allocates an available entry6412 and populates the allocated entry 6412, and the FSM updates theallocated entry 6412 state to requesting-NNU. The request arbiter 6416arbitrates among the requesting-NNU entries 6412. When the allocatedentry 6412 wins arbitration and is sent as a request to the NNU 121, theFSM marks the entry 6412 as pending-NNU-data. When the NNU 121 respondswith data for the request, the load queue 6312 loads the data into theentry 6412 and marks the entry 6412 as requesting-data-ring. The dataarbiter 6414 arbitrates among the requesting data-ring-entries 6412.When the entry 6412 wins arbitration and the data is sent on the ringbus 4024 to the ring bus 4024 agent that requested the data, the FSMmarks the entry 6412 available and emits a credit on its credit ring.

The slave store queue 6314 includes a queue of entries 6422 coupled to arequest arbiter 6426 and an acknowledge arbiter 6424. In the embodimentshown, the queue includes 16 entries 6422. Each entry 6422 includesstorage for an address, a source identifier, and data associated withthe request. The address specifies the location within the NNU 121 towhich the data provided by the requesting ring bus 4024 agent (e.g., acore 4002) is to be stored. The address may specify a control/statusregister 127, a block location within the data RAM 122 or weight RAM124, a location within the program memory 129, or a location within thebus control memory 6636. When the address specifies a block locationwithin the data/weight RAM 122/124, the upper bits specify a row of thedata/weight RAM 122/124, and the lower bits (e.g., 6 bits) specify ablock within the specified row. Preferably, the lower bits are used tocontrol the data/weight demultiplexer 6611/6621 to select theappropriate block within the data/weight write buffer 6612/6622 to write(see FIG. 45). The source identifier specifies the requesting ring bus4024 agent.

Each entry 6422 also has an associated state. A finite state machine(FSM) updates the state. In one embodiment, the FSM operates as follows.When the store queue 6314 detects a store request on the ring bus 4024destined for itself, the store queue 6314 allocates an available entry6422 and populates the allocated entry 6422, and the FSM updates theallocated entry 6422 state to requesting-NNU. The request arbiter 6426arbitrates among the requesting-NNU entries 6422. When the entry 6422wins arbitration and is sent to the NNU 121 along with the data of theentry 6422, the FSM marks the entry 6422 as pending-NNU-acknowledge.When the NNU 121 responds with an acknowledgement, the store FSM marksthe entry 6422 as requesting-acknowledge-ring. The acknowledge arbiter6424 arbitrates among the requesting-acknowledge-ring entries 6422. Whenthe entry 6422 wins arbitration and an acknowledgment is sent on theacknowledge ring to the ring bus 4024 agent that requested to store thedata, the FSM marks the entry 6422 available and emits a credit on itscredit ring. The store queue 6314 also receives a wr_busy signal fromthe NNU 121 that instructs the store queue 6314 not to request from theNNU 121 until the wr_busy signal is no longer active.

Referring now to FIG. 44, a block diagram illustrating in more detailthe master interface 0 6302-0 of FIG. 42 is shown. Although FIG. 44illustrates master interface 0 6302-0, it is also representative of thedetails of the master interface 1 6302-1 of FIG. 42 and will thereforebe referred to generically as master interface 6302. The masterinterface 6302 includes the load queue 6322 and store queue 6324 andarbiters 6362, 6364 and 6366 and buffers 6352, 6354 and 6356 coupled tothe ring bus 4024 of FIG. 42. FIG. 44 also illustrates other acknowledgerequestors 6576 (e.g., slave interface 6301) that generate acknowledgerequests to arbiter 6366.

The master interface 6302 also includes an arbiter 6534 (not shown inFIG. 42) that receives the requests from the load queue 6322 as well asfrom other requestors 6572 (e.g., the DRAM controller 4018 in anembodiment in which the NNU 121 and DRAM controller 4018 share the ringstop 4004-N), and presents the arbitration-winning request to arbiter6362 of FIG. 42. The master interface 6302 also includes a buffer 6544that receives data associated with a load queue 6312 entry 6512 from thering bus 4024 and provides it to the NNU 121. The master interface 6302also includes an arbiter 6554 (not shown in FIG. 42) that receives datafrom the store queue 6324 as well as from other requestors 6574 (e.g.,the DRAM controller 4018 in an embodiment in which the NNU 121 and DRAMcontroller 4018 share the ring stop 4004-N), and presents thearbitration-winning data to arbiter 6364 of FIG. 42. The masterinterface 6302 also includes a buffer 6564 that receives an acknowledgeassociated with a store queue 6314 entry 6522 from the ring bus 4024 andprovides it to the NNU 121.

The load queue 6322 includes a queue of entries 6512 coupled to anarbiter 6514. In the embodiment shown, the queue includes 16 entries6512. Each entry 6512 includes storage for an address and destinationidentifier. The address specifies an address in the ring bus 4024address space (e.g., of a system memory location), which is 46 bits inone embodiment. The destination identifier specifies the ring bus 4024agent from which the data will be loaded (e.g., system memory).

The load queue 6322 receives master load requests from the NNU 121(e.g., from a DMAC 6602) to load data from a ring bus 4024 agent (e.g.,system memory) into the data RAM 122, weight RAM 124, program memory 129or bus control memory 6636. The master load request specifies thedestination identifier, the ring bus address and the index of the loadqueue 6322 entry 6512 to be used. When the load queue 6322 receives amaster load request from the NNU 121, the load queue 6322 populates theindexed entry 6512, and the FSM updates the entry 6512 state torequesting credit. When the load queue 6322 obtains from the credit ringa credit to send a request for data to the destination ring bus 4024agent (e.g., system memory), the FSM updates the state torequesting-request-ring. The arbiter 6514 arbitrates among therequesting-request-ring entries 6512 (and arbiter 6534 arbitrates amongthe load queue 6322 and the other requestors 6572). When the entry 6512is granted the request ring, the request is sent on the request ring tothe destination ring bus 4024 agent (e.g., system memory), and the FSMupdates the state to pending-data-ring. When the ring bus 4024 respondswith the data (e.g., from system memory), it is received in buffer 6544and provided to the NNU 121 (e.g., to the data RAM 122, weight RAM 124,program memory 129 or bus control memory 6636), and the FSM updates theentry 6512 state to available. Preferably, the index of the entry 6512is included within the data packet to enable the load queue 6322 todetermine the entry 6512 with which the data packet is associated.Preferably, the load queue 6322 provides the entry 6512 index to the NNU121 along with the data to enable the NNU 121 to determine which entry6512 the data is associated with and to enable the NNU 121 to reuse theentry 6512.

The master store queue 6324 includes a queue of entries 6522 coupled toan arbiter 6524. In the embodiment shown, the queue includes 16 entries6522. Each entry 6522 includes storage for an address, a destinationidentifier, a data field for holding the data to be stored, and acoherent flag. The address specifies an address in the ring bus 4024address space (e.g., of a system memory location). The destinationidentifier specifies the ring bus 4024 agent to which the data will bestored (e.g., system memory). The coherent flag is sent to thedestination agent along with the data. If the coherent flag is set, itinstructs the DRAM controller 4018 to snoop the LLC 4005 and toinvalidate the copy in the LLC 4005 if present there. Otherwise, theDRAM controller 4018 writes the data to system memory without snoopingthe LLC 4005.

The store queue 6324 receives master store requests from the NNU 121(e.g., from a DMAC 6602) to store data to a ring bus 4024 agent (e.g.,system memory) from the data RAM 122 or weight RAM 124. The master storerequest specifies the destination identifier, the ring bus address, theindex of the store queue 6324 entry 6522 to be used, and the data to bestored. When the store queue 6324 receives a master store request fromthe NNU 121, the store queue 6324 populates the allocated entry 6522,and the FSM updates the entry 6522 state to requesting credit. When thestore queue 6324 obtains from the credit ring a credit to send data tothe destination ring bus 4024 agent (e.g., system memory), the FSMupdates the state to requesting-data-ring. The arbiter 6524 arbitratesamong the requesting-data-ring entries 6522 (and arbiter 6554 arbitratesamong the store queue 6324 and the other requestors 6574). When theentry 6522 is granted the data ring, the data is sent on the data ringto the destination ring bus 4024 agent (e.g., system memory), and theFSM updates the state to pending-acknowledgment-ring. When the ring bus4024 responds with an acknowledge (e.g., from system memory) of thedata, it is received in buffer 6564. The store queue 6324 then providesthe acknowledge to the NNU 121 to notify it that the store has beenperformed, and the FSM updates the entry 6522 state to available.Preferably, the store queue 6324 does not have to arbitrate to providethe acknowledge to the NNU 121 (e.g., there is a DMAC 6602 for eachstore queue 6324, as in the embodiment of FIG. 45). However, in anembodiment in which the store queue 6324 must arbitrate to provide theacknowledge, the FSM updates the entry 6522 state to requesting-NNU-donewhen the ring bus 4024 responds with the acknowledge, and once the entry6522 wins arbitration and provides the acknowledge to the NNU 121, theFSM updates the entry 6522 state to available. Preferably, the index ofthe entry 6522 is included within the acknowledge packet received fromthe ring bus 4024 which enables the store queue 6324 to determine theentry 6522 with which the acknowledge packet is associated. The storequeue 6324 provides the entry 6522 index to the NNU 121 along with theacknowledge to enable the NNU 121 to determine which entry 6522 the datais associated with and to enable the NNU 121 to reuse the entry 6522.

Referring now to FIG. 45, a block diagram illustrating the ring stop4004-N of FIG. 42 and portions of a ring bus-coupled embodiment of theNNU 121 is shown. The slave interface 6301, master interface 0 6302-0and master interface 1 6302-1 of the ring stop 4004-N are shown. Thering bus-coupled embodiment of the NNU 121 of FIG. 45 includes the dataRAM 122, weight RAM 124, program memory 129, sequencer 128,control/status registers 127 embodiments of which are described indetail above. The ring bus-coupled embodiment of the NNU 121 is similarin many respects to the execution unit embodiments described above andfor brevity those aspects will not be re-described. The ring bus-coupledembodiment of the NNU 121 also includes the elements described in FIG.40, e.g., the move unit 5802, move register 5804, mux-reg 208/705, NPUs126, muxes 5806, out units 5808, and out register 1104. The NNU 121 alsoincludes a first direct memory access controller (DMAC0) 6602-0, asecond direct memory access controller (DMAC1) 6602-1, the bus controlmemory 6636, data demultiplexers 6611, data write buffers 6612, a dataRAM multiplexer 6613, data read buffers 6614, data read buffermultiplexers 6615, weight demultiplexers 6621, weight write buffers6622, a weight RAM multiplexer 6623, weight read buffers 6624, weightread buffer multiplexers 6625, a slave multiplexer 6691, a master 0multiplexer 6693, and a master 1 multiplexer 6692. In one embodiment,there are three each of the data demultiplexers 6611, data write buffers6612, data read buffers 6614, data read buffer multiplexers 6615, weightdemultiplexers 6621, weight write buffers 6622, weight read buffers6624, and weight read buffer multiplexers 6625 respectively associatedwith the slave interface 6301, the master interface 0 6302-0 and themaster interface 1 6302-1 of the ring bus 4024. In one embodiment, thereis a pair of three each of the data demultiplexers 6611, data writebuffers 6612, data read buffers 6614, data read buffer multiplexers6615, weight demultiplexers 6621, weight write buffers 6622, weight readbuffers 6624, and weight read buffer multiplexers 6625 respectivelyassociated with the slave interface 6301, the master interface 0 6302-0and the master interface 1 6302-1 of the ring bus 4024 to support datatransfers in a double-buffering fashion.

The data demultiplexers 6611 are respectively coupled to receive datablocks from the slave interface 6301, the master interface 0 6302-0 andthe master interface 1 6302-1. The data demultiplexers 6611 are alsorespectively coupled to the data write buffers 6612, which are coupledto the data RAM multiplexer 6613, which is coupled to the data RAM 122,which is coupled to the data read buffers 6614, which are respectivelycoupled to the data read buffer multiplexers 6615, which are coupled tothe slave mux 6691, the master 0 multiplexer 6693 and the master 1multiplexer 6692. The slave mux 6691 is coupled to the slave interface6301, the master 0 multiplexer 6693 is coupled to the master interface 06302-0, and the master 1 multiplexer 6692 is coupled to the masterinterface 1 6302-1. The weight demultiplexers 6621 are respectivelycoupled to receive data blocks from the slave interface 6301, the masterinterface 0 6302-0, and the master interface 1 6302-1. The weightdemultiplexers 6621 are also respectively coupled to the weight writebuffers 6622, which are coupled to the weight RAM multiplexer 6623,which is coupled to the weight RAM 124, which is coupled to the weightread buffers 6624, which are respectively coupled to the weight readbuffer multiplexers 6625, which are coupled to the slave mux 6691, themaster 0 multiplexer 6693 and the master 1 multiplexer 6692. The dataRAM multiplexer 6613 and weight RAM multiplexer 6623 are also coupled tothe out register 1104 and move register 5804. The data RAM 122 andweight RAM 124 are also coupled to the move unit 5802 and the datamux-regs 208 and weight mux-regs 705, respectively, of the NPUs 126. Thecontrol/status registers 127 are coupled to the slave interface 6301.The bus control memory 6636 is coupled to the slave interface 6301,sequencer 128, DMAC0 6602-0, and DMAC1 6602-1. The program memory 129 iscoupled to the slave interface 6301 and sequencer 128. The sequencer 128is coupled to the program memory 129, bus control memory 6636, NPUs 126,move unit 5802, and out units 5808. DMAC0 6602-0 is also coupled tomaster interface 0 6302-0, and DMAC1 6602-1 is also coupled to masterinterface 1 6302-1.

The data write buffers 6612, data read buffers 6614, weight writebuffers 6622 and weight read buffers 6624 are the width of the data RAM122 and weight RAM 124, which is the width of the NPU 126 array,typically referred to as N herein. Thus, for example, in one embodimentthere are 4096 NPUs 126 and the data write buffers 6612, data readbuffers 6614, weight write buffers 6622 and weight read buffers 6624 are4096 bytes wide, although other embodiments are contemplated in which Nis other than 4096. The data RAM 122 and weight RAM 124 are written anentire N-word row at a time. The out register 1104, the move register5804, and the data write buffers 6612 write to the data RAM 122 via thedata RAM multiplexer 6613, which selects one of them for writing a rowof words to the data RAM 122. The out register 1104, the move register5804, and the weight write buffers 6622 write to the weight RAM 124 viathe weight RAM multiplexer 6623, which selects one of them for writing arow of words to the weight RAM 124. Control logic (not shown) controlsthe data RAM multiplexer 6613 to arbitrate between the data writebuffers 6612, the move register 5804 and the out register 1104 foraccess to the data RAM 122, and controls the weight RAM multiplexer 6623to arbitrate between the weight write buffers 6622, the move register5804 and the out register 1104 for access to the weight RAM 124. Thedata RAM 122 and weight RAM 124 are also read an entire N-word row at atime. The NPUs 126, the move unit 5802, and the data read buffers 6614read a row of words from the data RAM 122. The NPUs 126, the move unit5802, and the weight read buffers 6624 read a row of words from theweight RAM 124. The control logic also controls the NPUs 126 (datamux-regs 208 and weight mux-regs 705), the move unit 5802, and the dataread buffers 6614 to determine which of them, if any, reads a row ofwords output by the data RAM 122. In one embodiment, the micro-operation3418 described with respect to FIG. 34 may include at least some of thecontrol logic signals that control the data RAM multiplexer 6613, weightRAM multiplexer 6623, NPUs 126, move unit 5802, move register 5804, outregister 1104, data read buffers 6614, and weight read buffers 6624.

The data write buffers 6612, data read buffers 6614, weight writebuffers 6622 and weight read buffers 6624 are addressable in blocks thatare block-size aligned. Preferably, the block size of the data writebuffers 6612, data read buffers 6614, weight write buffers 6622 andweight read buffers 6624 matches the width of the ring bus 4024 Datasub-ring. This accommodates the ring bus 4024 to read/write thedata/weight RAM 122/124 as follows. Typically, the ring bus 4024performs block-sized writes to each block of a data write buffer 6612and, once all the blocks of the data write buffer 6612 have been filled,the data write buffer 6612 writes its N-word contents to an entire rowof the data RAM 122. Similarly, the ring bus 4024 performs block-sizedwrites to each block of a weight write buffer 6622 and, once all theblocks of the weight write buffer 6622 have been filled, the weightwrite buffer 6622 writes its N-word contents to an entire row of theweight RAM 124. In one embodiment, the NNU 121 includes a row addressregister (not shown) associated with each data/weight write buffer6612/6622. Each time the ring stop 4004-N writes a block to thedata/weight write buffer 6612/6622, the row address register is updated.However, before the row address register is updated, its current valueis compared to the new value, and if the two values are not the same,i.e., a new row of the data/weight RAM 122/124 is being written, thistriggers a write of the data/weight write buffer 6612/6622 to thedata/weight RAM 122/124. In one embodiment, a write to the programmemory 129 also triggers a write of the data/weight write buffer6612/6622 to the data/weight RAM 122/124. Conversely, an N-word row isread from the data RAM 122 into a data read buffer 6614; then the ringbus 4024 performs block-sized reads from each block of the data readbuffer 6614. Similarly, an N-word row is read from the weight RAM 124into a weight read buffer 6624; then the ring bus 4024 performsblock-sized reads from each block of the weight read buffer 6624.Although the data RAM 122 and weight RAM 124 appear as dual-portedmemories in FIG. 45, preferably they are single-ported memories suchthat the single data RAM 122 port is shared by the data RAM multiplexer6613 and the data read buffers 6614, and single weight RAM 124 port isshared by the weight RAM multiplexer 6623 and the weight read buffers6624. Thus, an advantage of the entire row read/write arrangement isthat it enables the data RAM 122 and weight RAM 124 to be smaller byhaving a single port (in one embodiment, the weight RAM 124 is 8 MB andthe data RAM 122 is 64 KB) and yet the writes to and reads from the dataRAM 122 and weight RAM 124 by the ring bus 4024 consume less bandwidththan they otherwise would if individual blocks were written, thusfreeing up more bandwidth for the NPUs 126, out register 1104, moveregister 5804, and move unit 5802 to make their N-word-wide rowaccesses.

The control/status registers 127 are provided to the slave interface6301. The slave mux 6691 receives the output of the data read buffermultiplexer 6615 associated with the slave interface 6301 and the outputof the weight read buffer multiplexer 6625 associated with the slaveinterface 6301 and selects one of them for provision to the slaveinterface 6301. In this manner, the slave load queue 6312 receives datafor responding to load requests made by the slave interface 6301 to thecontrol/status registers 127, data RAM 122 or weight RAM 124. The master0 multiplexer 6693 receives the output of the data read buffermultiplexer 6615 associated with the master interface 0 6302-0 and theoutput of the weight read buffer multiplexer 6625 associated with themaster interface 0 6302-0 and selects one of them for provision to themaster interface 0 6302-0. In this manner, the master interface 0 6302-0receives data for responding to store requests made by the masterinterface 0 6302-0 store queue 6324. The master 1 multiplexer 6692receives the output of the data read buffer multiplexer 6615 associatedwith the master interface 1 6302-1 and the output of the weight readbuffer multiplexer 6625 associated with the master interface 1 6302-1and selects one of them for provision to the master interface 1 6302-1.In this manner, the master interface 1 6302-1 receives data forresponding to store requests made by the master interface 1 6302-1 storequeue 6324. If the slave interface 6301 load queue 6312 requests to readfrom the data RAM 122, the slave multiplexer 6691 selects the output ofthe data read buffer multiplexer 6615 associated with the slaveinterface 6301; whereas, if the slave interface 6301 load queue 6312requests to read from the weight RAM 124, the slave multiplexer 6691selects the output of the weight read buffer multiplexer 6625 associatedwith the slave interface 6301. Similarly, if the master interface 06302-0 store queue requests to read data from the data RAM 122, themaster 0 multiplexer 6693 selects the output of the data read buffermultiplexer 6615 associated with the master interface 0 6302-0; whereas,if the master interface 0 6302-0 store queue requests to read data fromthe weight RAM 124, the master 0 multiplexer 6693 selects the output ofthe weight read buffer multiplexer 6625 associated with the masterinterface 0 6302-0. Finally, if the master interface 1 6302-1 storequeue requests to read data from the data RAM 122, the master 1multiplexer 6692 selects the output of the data read buffer multiplexer6615 associated with the master interface 1 6302-1; whereas, if themaster interface 1 6302-1 store queue requests to read data from theweight RAM 124, the master 1 multiplexer 6692 selects the output of theweight read buffer multiplexer 6625 associated with the master interface1 6302-1. Thus, a ring bus 4024 agent (e.g., a core 4002) may read fromthe control/status registers 127, data RAM 122 or weight RAM 124 via theslave interface 6301 load queue 6312. Additionally, a ring bus 4024agent (e.g., a core 4002) may write to the control/status registers 127,data RAM 122, weight RAM 124, program memory 129, or bus control memory6636 via the slave interface 6301 store queue 6314. More specifically, acore 4002 may write a program (e.g., that performs fully-connected,convolution, pooling, LSTM or other recurrent neural network layercomputations) to the program memory 129 and then write to acontrol/status register 127 to start the program. Additionally, a core4002 may write control words to the bus control memory 6636 to cause theDMACs 6602 to perform DMA operations between the data RAM 122 or weightRAM 124 and a ring bus 4024 agent, e.g., system memory or the LLC 4005.The sequencer 128 may also write control words to the bus control memory6636 to cause the DMACs 6602 to perform DMA operations between the dataRAM 122 or weight RAM 124 and a ring bus 4024 agent. Finally, the DMACs6602 may perform DMA operations to perform transfers between a ring bus4024 agent (e.g., system memory or the LLC 4005) and the data/weight RAM122/124, as described in more detail below.

The slave interface 6301, master interface 0 6302-0 and master interface1 6302-1 are each coupled to provide a block of data to their respectivedata demultiplexer 6611 and respective weight demultiplexer 6621.Arbitration logic (not shown) arbitrates between the out register 1104,the move register 5804 and the slave interface 6301, master interface 06302-0 and master interface 1 6302-1 data write buffers 6612 and foraccess to the data RAM 122 and arbitrates between the out register 1104,the move register 5804 and the slave interface 6301, master interface 06302-0 and master interface 1 6302-1 weight write buffers 6622 and foraccess to the weight RAM 124. In one embodiment, the write buffers6612/6622 have priority over the out register 1104 and the move register5804, and the slave interface 6301 has priority over the masterinterfaces 6302. In one embodiment, each of the data demultiplexers 6611has 64 outputs (preferably 64 bytes each) coupled to the 64 blocks ofits respective data write buffer 6612. The data demultiplexer 6611provides the received block on the output coupled to the appropriateblock of the data write buffer 6612. Similarly, each of the weightdemultiplexers 6621 has 64 outputs (preferably 64 bytes each) coupled tothe 64 blocks of its respective weight write buffer 6622. The weightdemultiplexer 6621 provides the received block on the output coupled tothe appropriate block of the weight write buffer 6622.

When the slave store queue 6314 provides a data block to its data/weightdemultiplexer 6611/6621, it also provides as the control input to thedata/weight demultiplexer 6611/6621 the address of the appropriate blockof the data/weight write buffer 6612/6622 that is to be written. Theblock address is the lower six bits of the address held in the entry6422, which was specified by the ring bus 4024 agent (e.g., core 4002)that generated the slave store transaction. Conversely, when the loadstore queue 6312 requests a data block from its data/weight read buffermultiplexer 6615/6625, it also provides as the control input to thedata/weight read buffer multiplexer 6615/6625 the address of theappropriate block of the data/weight read buffer 6614/6624 that is to beread. The block address is the lower six bits of the address held in theentry 6412, which was specified by the ring bus 4024 agent (e.g., core4002) that generated the slave load transaction. Preferably, a core 4002may perform a slave store transaction via the slave interface 6301(e.g., to a predetermined ring bus 4024 address) to cause the NNU 121 towrite the contents of the data/weight write buffer 6612/6622 to thedata/weight RAM 122/124; conversely, a core 4002 may perform a slavestore transaction via the slave interface 6301 (e.g., to a predeterminedring bus 4024 address) to cause the NNU 121 to read a row of thedata/weight RAM 122/124 into a data/weight read buffer 6614/6624.

When a master interface 6302 load queue 6322/6332 provides a data blockto its data/weight demultiplexer 6611/6621, it also provides the indexof the entry 6512 to the corresponding DMAC 6602 that issued the loadrequest to the load queue 6322/6332. To transfer an entire 4 KB of datafrom the system memory to a row of the data/weight RAM 122/124, the DMAC6602 must generate 64 master load requests to the load queue 6322/6332.The DMAC 6602 logically groups the 64 master load requests into fourgroups of sixteen requests each. The DMAC 6602 makes the sixteenrequests within a group to the respective sixteen entries 6512 of theload queue 6322/6322. The DMAC 6602 maintains state associated with eachentry 6512 index. The state indicates which group of the four groups forwhich the entry is currently being used to load a block of data. Thus,when the DMAC 6602 receives the entry 6512 index from the load queue6322/6322, logic of the DMAC 6602 constructs the block address byconcatenating the group number to the index and provides the constructedblock address as the control input to the data/weight demultiplexer6611/6621, as described in more detail below.

Conversely, when a master interface 6302 store queue 6324/6334 requestsa data block from its data/weight read buffer multiplexer 6615/6625, italso provides the index of the entry 6522 to the corresponding DMAC 6602that issued the store request to the store queue 6324/6334. To transferan entire 4 KB of data to the system memory from a row of thedata/weight RAM 122/124, the DMAC 6602 must generate 64 master storerequests to the store queue 6324/6334. The DMAC 6602 logically groupsthe 64 store requests into four groups of sixteen requests each. TheDMAC 6602 makes the sixteen requests within a group to the respectivesixteen entries 6522 of the store queue 6324/6334. The DMAC 6602maintains state associated with each entry 6522 index. The stateindicates which group of the four groups for which the entry iscurrently being used to store a block of data. Thus, when the DMAC 6602receives the entry 6522 index from the store queue 6324/6334, logic ofthe DMAC 6602 constructs the block address by concatenating the groupnumber to the index and provides the constructed block address as thecontrol input to the data/weight read buffer multiplexer 6615/6625, asdescribed in more detail below.

Referring now to FIG. 46, a block diagram illustrating a ringbus-coupled embodiment of the NNU 121 is shown. FIG. 46 is similar insome ways to FIG. 34 and similarly numbered elements are similar. LikeFIG. 34, FIG. 46 illustrates the capability of the NNU 121 to receivemicro-operations from multiple sources for provision to its pipeline.However, in the embodiment of FIG. 46, the NNU 121 is coupled to cores4002 via the ring bus 4024 as in FIG. 41, and differences will now bedescribed.

In the embodiment of FIG. 46, the multiplexer 3402 receives amicro-operation from five different sources. The multiplexer 3402provides the selected micro-operation 3418 to the NPU 126 pipelinestages 3401, the data RAM 122 and weight RAM 124, the move unit 5802,and out units 5808 to control them, as described above. The first sourceis the sequencer 128 that generates a micro-operation 3416, as describedwith respect to FIG. 34. The second source is a modified version of thedecoder 3404 of FIG. 34 that receives a data block of a store requestfrom the slave interface 6301 store queue 6314 stored by a core 4002.The data block may include information similar to the microinstructiontranslated from an MTNN instruction 1400 or MFNN instruction 1500, asdescribed above with respect to FIG. 34. The decoder 3404 decodes thedata block and in response generates a micro-operation 3412. An exampleis a micro-operation 3412 generated in response to a request receivedfrom the slave interface 6301 store queue 6314 to write data to thedata/weight RAM 122/124 or in response to a request received from theslave interface 6301 load queue 6312 to read data from the data/weightRAM 122/124. The third source is a direct data block of a store requestfrom the slave interface 6301 store queue 6314 stored by a core 4002that includes a micro-operation 3414 that the NNU 121 directly executes,as described above with respect to FIG. 34. Preferably, the core 4002stores to different memory-mapped addresses in the ring bus 4024 addressspace to enable the decoder 3404 to distinguish between the second andthird micro-operation sources. The fourth source is a micro-operation7217 generated by the DMACs 6602. The fifth source is a no-operationmicro-operation 7219, in response to which the NNU 121 retains itsstate.

In one embodiment, the five sources have a priority scheme enforced bythe decoder 3404 in which the direct micro-operation 3414 has highestpriority; the micro-operation 3412 generated by the decoder 3404 inresponse to the slave store operation by the slave interface 6301 hassecond highest priority; the micro-operation 7217 generated by a DMAC6602 has next highest priority; the micro-operation 3416 generated bythe sequencer 128 has next highest priority; and the no-opmicro-operation is the default, i.e., lowest priority, source which themultiplexer 3402 selects when none of the other sources are requesting.According to one embodiment, when a DMAC 6602 or the slave interface6301 needs to access the data RAM 122 or weight RAM 124, it has priorityover the program running on the sequencer 128, and the decoder 3404causes the sequencer 128 to pause until the DMAC 6602 and slaveinterface 6301 have completed their accesses.

Interrupts to Core Upon Condition

As described above, the NNU 121 may generate interrupt requests to acore 4002. The interrupt request may notify the core 4002 of events thathave occurred so the core 4002 can take action accordingly. Thefollowing are examples of events associated with an interrupt requestfrom the NNU 121 to a core 4002.

First, the NNU 121 may generate results (e.g., the outputs of a neuralnetwork layer) available for the core 4002 to access. The results may beavailable in the data RAM 122 or weight RAM 124 for the core 4002 toread; or, the NNU 121 may have transferred the results to system memory(e.g., using one of the DMACs 6602). Second, the program currentlyrunning on the NNU 121 may need the core 4002 to provide more input datato process, e.g., for a new time step (e.g., in a recurring neuralnetwork (RNN), such as an LSTM layer), for a new layer of the network,or for a different set of nodes within the current layer of the network(e.g., in which the number of neurons in the layer is greater than thenumber of NPUs 126 in the NNU 121). The core 4002 may provide the databy writing it to the data/weight RAM 122/124, for example; or, the core4002 may inform the NNU 121 of the location of the data in system memoryso that the NNU 121 can transfer the data from the system memory to thedata/weight RAM 122/124. Third, the core 4002 may need to provide moreweights for neural network computations, e.g., for a new network layeror for a different set of nodes within the current layer of the network(e.g., in which the number of neurons in the layer is greater than thenumber of NPUs 126 in the NNU 121). Again, the core 4002 may provide theweights by writing them to the data/weight RAM 122/124, for example; or,the core 4002 may inform the NNU 121 of the location of the weights insystem memory so that the NNU 121 can transfer the weights from thesystem memory to the data/weight RAM 122/124. Fourth, the core 4002 mayneed to provide a new program for the NNU 121 to execute, i.e., a newprogram for loading into the program memory 129. Again, the core 4002may provide the program by writing it to the program memory 129; or, thecore 4002 may inform the NNU 121 of the location of the program insystem memory so that the NNU 121 can transfer the program from thesystem memory to the program memory 129. Fifth, the NNU 121 may simplyneed to let the core 4002 know the program is finished.

A problem is that in many systems, depending upon the instruction setarchitecture of the core 4002 and/or the operating system running on thecore 4002, there may a relatively large interrupt latency, which is thetime required from the generation of the interrupt request to a core4002 by an apparatus of the system, such as the NNU 121, until the core4002 reads state of the apparatus to determine the occurrence of anevent associated with the interrupt request. The interrupt latency mayresult in a relatively large amount of time in which the apparatus issitting idle. This relatively low utilization of the apparatus may beparticularly disadvantageous to the performance of the system,particularly where the apparatus is an accelerator, such as a neuralnetwork computation accelerator like the NNU 121.

Embodiments are described that enable the NNU 121 to reduce the latencyby the NNU 121 executing a set interrupt condition instruction,preferably at the beginning of a program, that sets an interruptcondition which, when satisfied, causes the NNU 121 to interrupt thecore 4002, although the program continues to run. Preferably, theinterrupt condition may be dynamically programmed with a combination ofvalues of the operational state of the NNU 121. In each of the casesdescribed above, it is typically beneficial for the NNU 121 to interruptthe core 4002 some number of clock cycles before the interruptrequest-associated event, namely approximately the number of clocks fromthe time at which the NNU 121 asserts the interrupt request signal untilexecution of the first instruction of the interrupt service routine thataccesses the NNU 121 to respond to the interrupt request-associatedevent, e.g., to read a status register in the NNU 121 to determinewhether the event has in fact completed, or to begin writing/readingdata/weights to/from the data/weight RAM 122/124, or to send the NNU 121a pointer to the address of data/weights to be read/written into/fromthe data/weight RAM 122/124, or to begin writing a program into theprogram memory 129.

Referring now to FIG. 47, a block diagram illustrating an embodiment ofa NNU 121 is shown. The NNU 121 is similar in many respects to the NNU121 embodiments described above and like-numbered elements are similar,with differences described herein. In particular, the NNU 121 includes adata RAM 122, weight RAM 124, program memory 129, sequencer 128 and NPU126 array similar to those described above. In addition, the NNU 121includes an interrupt condition register 4706, a status register 4704,and control logic 4702. The interrupt condition register 4706 and statusregister 4704 are coupled to the sequencer 128 and to the control logic4702. The status register 4704 holds a status of the NNU 121 during itsoperation. The status may be comprised of various fields, embodiments ofwhich are described in more detail below with respect to FIG. 49. A setinterrupt condition instruction 4722, stored in the program memory 129and fetched by the sequencer 128, writes an interrupt condition to theinterrupt condition register 4706. The interrupt condition, embodimentsof which are described in more detail below with respect to FIG. 48, maybe comprised of a combination of various fields that correspond to thestatus fields. The combination may be chosen by each set interruptcondition instruction 4722. The control logic 4702 has an output uponwhich it generates an interrupt request 4712 to a processing core 4002when the status satisfies the interrupt condition, as described in moredetail below. Although FIG. 47 shows only the sequencer 128 updating thestatus register 4704, the various fields of the status register 4704 mayalso be updated by operation of other elements of the NNU 121.Preferably, the NNU 121 includes multiple interrupt condition registers4706 to enable the program to set multiple interrupt conditions.

Referring now to FIG. 48, a block diagram illustrating in more detailthe interrupt condition register 4706 of FIG. 47 is shown. The interruptcondition register 4706 includes the following fields: a weight RAMwrite address 4802, a weight RAM read address 4804, a data RAM writeaddress 4806, a data RAM read address 4808, a program counter 4812, aloop count 4814, and an iteration count 4816, also referred to as arepeat count 4816. Each of the fields has a corresponding valid bit,denoted V in FIG. 48. When determining whether the status held in thestatus register 4704 satisfies the interrupt condition, the controllogic 4702 only considers the fields of the status register 4704 whosecorresponding fields of the interrupt condition register 4706 whosevalid bits are set, as described in more detail below.

The weight RAM write address 4802, weight RAM read address 4804, dataRAM write address 4806, data RAM read address 4808, program counter4812, loop count 4814, and iteration count 4816 fields correspond tosimilarly-named fields in the status register 4704, as described in moredetail below. Preferably, the status held in the status register 4704satisfies the interrupt condition specified in the interrupt conditionregister 4706 when, for each field of the interrupt condition register4706 whose valid bit is set, the value of the interrupt condition fieldmatches the value of its corresponding status field in the statusregister 4704, for as example as with respect to block 5012 of FIG. 50.In this manner, the interrupt condition may be viewed as the combinedvalues of the valid fields of the interrupt condition register 4706.

Referring now to FIG. 49, a block diagram illustrating in more detailthe status register 4704 of FIG. 47 is shown. The status register 4704includes the following fields: a weight RAM write address 4902, a weightRAM read address 4904, a data RAM write address 4906, a data RAM readaddress 4908, a program counter 4912 (also referred to as program memoryaddress 4912), a loop count 4914, and an iteration count 4916, alsoreferred to as a repeat count 4916. The weight RAM write address 4902,weight RAM read address 4904, data RAM write address 4906, data RAM readaddress 4908, program counter 4912, loop count 4914, and iteration count4916 hold values that indicate operational state of the NNU 121. Thatis, they are updated during operation of the NNU 121. Preferably, thevalues are similar to the fields described above with respect to thestatus register 127 of FIG. 39. The weight RAM write address 4902specifies the address of the most recently written weight RAM 124 row(e.g., address 125 of FIG. 47). The weight RAM read address 4904specifies the address of the most recently read weight RAM 124 row(e.g., address 125 of FIG. 47). The data RAM write address 4906specifies the address of the most recently written data RAM 122 row(e.g., address 123 of FIG. 47). The data RAM read address 4908 specifiesthe address of the most recently read data RAM 122 row (e.g., address123 of FIG. 47). The data RAM 122 and weight RAM 124 may be read andwritten by the by the NPUs 126 or ring stop 4004-N, e.g., via the outregister 1104, move register 5804, move unit 5802, write buffers6612/6622 and/or read buffers 6614/6624. The program counter 4912specifies the address (e.g., address 131 of FIG. 47) at which the mostrecent instruction is fetched from the program memory 129 (e.g., thevalue of the program counter 3802 of FIG. 38) by the sequencer 128. Theloop count 4914 indicates the number of times a loop of the programremains to be executed (e.g., the value of the loop counter 3804 of FIG.38). The iteration count 4916 indicates the number of times theoperation specified in a current program instruction remains to beperformed (e.g., the value of the iteration counter 3806 of FIG. 47).

Referring now to FIG. 50, a flowchart illustrating operation of the NNU121 of FIG. 47 to generate an interrupt request to a core 4002 basedupon conditions is shown. Flow begins at block 5002.

At block 5002, the sequencer 128 fetches a set interrupt conditioninstruction 4722 from the program memory 129 at the program counter 3802address 131 and decodes the instruction 4722. The set interruptcondition instruction 4722 specifies an interrupt condition. Flowproceeds to block 5004.

At block 5004, in response to decoding the set interrupt conditioninstruction 4722, the sequencer 128 generates a micro-operation 3416that writes the interrupt condition specified in the set interruptcondition instruction 4722 to the interrupt condition register 4706.Flow proceeds to block 5006.

At block 5006, the sequencer 128 continues to fetch and decodeinstructions from the program memory 129 and generate micro-operations3416 executed by the NPUs 126. This causes a change in the state of theNNU 121, including updates to the status register 4704, e.g., to theprogram counter 4912, loop count 3914, iteration count 4916, anddata/weight RAM read/write addresses 4908/4906/4904/4902. Flow proceedsto block 5008.

At block 5008, the control logic 4702 monitors the status register 4704to see if its status satisfies the interrupt condition specified in theinterrupt condition register 4706. Preferably, the status held in thestatus register 4704 satisfies the interrupt condition when, for eachfield of the interrupt condition register 4706 whose valid bit is set,the value of the interrupt condition field matches the value of itscorresponding status field in the status register 4704. Flow proceeds todecision block 5012.

At decision block 5012, if the status satisfies the interrupt condition,flow proceeds to block 5014; otherwise, flow returns to block 5008.

At block 5014, the control logic 4702 generates an interrupt request4712 to the core 4002. Flow ends at block 5014.

Referring now to FIG. 51, a table illustrating a program for storage inthe program memory 129 of and execution by the NNU 121 of FIG. 47 isshown. The example program performs calculations associated with a layerof an artificial neural network as described above. For example, theprogram may be used to perform multiply-accumulate calculationsassociated with a fully-connected neural network layer in which 30different instances of input data to the layer are stored in rows 0through 29 of the data RAM 122, and associated weights are stored in therows 0 through 511 of the weight RAM 124, and the NNU 121 writes the 30outputs of the layer corresponding to the 30 input data instances torows 30 through 59 of the data RAM 122. To accomplish this, the programincludes a loop body that is performed 30 times, as specified by theloop count of 30 in the initialize instruction at address 0. Eachexecution instance of the loop body performs 512 multiply-accumulateoperations and outputs a result to a different row of the data RAM 122,similar to that described above with respect to FIG. 4 (in the exampleof FIG. 4 different data RAM 122 addresses are used and there is noloop). In the example, it is assumed that the interrupt latency of thecore 4002 is approximately 600 clock cycles and that it is desirable forthe core 4002 to begin to read the 30 outputs from the data RAM 122 justafter the thirtieth output is written to the data RAM 122, which isreferred to as the interrupt request-associated event here. That is, itis desirable for the NNU 121 to generate an interrupt request 4712 tothe core 4002 approximately 600 clocks before the interruptrequest-associated event. Advantageously, the program includes a setinterrupt condition instruction 4722 (at address 1) that specifies aninterrupt condition to cause the NNU 121 to generate an interruptrequest 4712 to the core 4002 approximately 600 clock cycles before theinterrupt request-associated event, which is a write of the thirtiethoutput to row 59 of the data RAM 122.

At address 0, the initialize instruction specifies a loop count value of30, which is the number of times each NPU 126 executes the loop bodycomprising the instructions at addresses 2 through 4. The loopinstruction at the end of the loop (at address 5) decrements the loopcount 4914 value and if the result is non-zero causes control to returnto the top of the loop body (i.e., to the instruction at address 2).Preferably, the initialize instruction also clears the accumulator 202to zero. Preferably, the loop instruction at address 5 also clears theaccumulator 202 to zero. Alternatively, the multiply-accumulateinstruction at address 2 may specify to clear the accumulator 202 tozero. The initialize instruction also initializes the data RAM 122 rowto zero and the data RAM 122 output row to 30 so that rows zero through29 are read and rows 30 through 59 are written for the 30 respectiveexecution instances of the loop body.

At address 1, the set interrupt condition instruction 4722 loads theinterrupt condition register 4706 with a condition specified by the setinterrupt condition instruction 4722. In the example of FIG. 51, thecondition is the combination of: the program counter 4912 equals thevalue of a LABEL1 (which is 3, i.e., the address of themultiply-accumulate instruction at the LABEL1), the loop count 4914equals 1, and the repeat count 4916 equals 14. As will be explainedbelow, these values cause the NNU 121 to generate an interrupt request4712 to the core 4002 approximately 600 clocks before the interruptrequest-associated event occurs in which the NNU 121 writes the resultof the last (thirtieth) execution instance of the loop body to row 59 ofthe data RAM 122.

At addresses 2 and 3, the multiply-accumulate instructions collectivelyperform 512 multiply-accumulate operations on a single row of data readfrom the data RAM 122 that is rotated among the NPUs 126 with 512 rowsof weights read from 512 different rows of the weight RAM 124 togenerate results accumulated into the accumulators 202 of the NPUs 126,as described in detail above, e.g., similar to the manner describedabove with respect to FIG. 4. More specifically, the instruction ataddress 3 specifies a repeat count of 511.

At address 4, the accumulated results of the multiply-accumulates areoutput to the current data RAM 122 row, which is 30 on the firstexecution instance of the loop, and which is 59 on the last/thirtiethexecution instance. In one embodiment, the output instruction performsan activation function on the accumulator 202 value before it writes theresult to the data RAM 122.

As may be understood from the program of FIG. 51 and the descriptionabove, preferably each execution instance of the loop body requiresapproximately 514 clock cycles (1 clock for the multiply-accumulate ataddress 2, 511 clocks for the multiply-accumulate at address 3, 1 clockfor the output instruction at address 4, and 1 clock for the loopinstruction at address 5). In the example, assume the interrupt latencyof the core 4002 is approximately 600 clock cycles. As a result,advantageously, the control logic 4702 will generate an interruptrequest 4712 to the core 4002 approximately 600 clock cycles before theinterrupt request-associated event, i.e., the write of the thirtiethoutput to data RAM 122 row 59. This is because when the program counter4912 equals 3 and the loop count 4914 equals 1 and the repeat count 4916equals 86 (i.e., which is when the control logic 4702 generates theinterrupt request 4712), then the NNU 121 typically will spend 86 moreclocks executing the last 86 iterations of the multiply-accumulate ataddress 3; then spend 2 clocks executing the instructions at addresses 4and 5; then on the last instance of the loop, spend one clock executingthe instruction at address 2; then spend 511 clocks on the instructionat address 3, then 1 clock on the instruction at address 4, which writesthe thirtieth output to data RAM 122 row 59, for a total ofapproximately 600 clocks. In the example, it is assumed the clock cycleof the NNU 121 and the core 4002 are the same. However, otherembodiments are contemplated in which they are different. In such anembodiment, the values of the interrupt condition are selected toaccount for the differences in the clock cycles of the NNU 121 and core4002.

Referring now to FIG. 52, a set interrupt condition instruction 4722according to an alternate embodiment for storage in the program memory129 of and execution by the NNU 121 of FIG. 47 is shown. The setinterrupt condition instruction 4722 of FIG. 52 may be substituted intothe program of FIG. 51 at address 1 to accomplish a similar result asthat of FIG. 51, but by using a different interrupt condition. Theinterrupt condition specified in FIG. 52 is that the data RAM writeaddress 4906 equals 57 and the repeat count 4916 equals 86. During thetwenty-eighth execution instance of the loop, the output instruction ataddress 4 will write the twenty-eighth output to row 57 of the data RAM122. Then, during the twenty-ninth execution instance of the loop andduring execution of the instruction at address 3, the repeat count 4916will decrement down to a value of 86, which will cause the control logic4702 to generate the interrupt request 4712 to the core 4002. This willbe approximately 600 clocks before the interrupt request-associatedevent, i.e., the write of the thirtieth output to data RAM 122 row 59.This is because when the data RAM write address 4906 equals 57 and therepeat count 4916 equals 86 (i.e., which is when the control logic 4702generates the interrupt request 4712), then the NNU 121 typically willspend 86 more clocks executing the last 86 iterations of themultiply-accumulate at address 3; then spend 2 clocks executing theinstructions at addresses 4 and 5; then on the last instance of theloop, spend one clock executing the instruction at address 2; then spend511 clocks on the instruction at address 3, then 1 clock on theinstruction at address 4, which writes the thirtieth output to data RAM122 row 59, for a total of approximately 600 clocks.

Referring now to FIG. 53, a table illustrating a program for storage inthe program memory 129 of and execution by the NNU 121 of FIG. 47 isshown. The example program performs calculations associated with a layerof an artificial neural network as described above. For example, theprogram may be used to perform a convolution of a data matrix with aconvolution kernel (e.g., each of FIG. 24) and write it back to theweight RAM 124, as described with respect to the program of FIG. 26. Toaccomplish this, the program includes a loop body that is performed 400times, as specified by the loop count of 400 in the initializeinstruction at address 0. Each execution instance of the loop bodyperforms 9 multiply-accumulate operations (instructions at addresses 2through 7), outputs a result to a different row of the weight RAM 124(instruction at address 8), decrements the weight RAM 124 row register(instruction at address 9), and loops back to the top of the loop body(instruction at address 10). Thus, each execution instance of the loopbody takes approximately 12 clock cycles.

Again, in the example, it is assumed that the interrupt latency of thecore 4002 is approximately 600 clock cycles and that it is desirable forthe core 4002 to begin to read the 400 outputs from the weight RAM 124just after the four-hundredth output is written to the weight RAM 124,which is referred to as the interrupt request-associated event here.That is, it is desirable for the NNU 121 to generate an interruptrequest 4712 to the core 4002 approximately 600 clocks before theinterrupt request-associated event. Advantageously, the program includesa set interrupt condition instruction 4722 (at address 1) that specifiesan interrupt condition to cause the NNU 121 to generate an interruptrequest 4712 to the core 4002 approximately 600 clock cycles before theinterrupt request-associated event.

In the example of FIG. 53, the set interrupt condition instruction 4722loads the interrupt condition register 4706 with an interrupt conditionthat is: the loop count 4914 equals 50. This interrupt condition valuecauses the NNU 121 to generate an interrupt request 4712 to the core4002 approximately 600 clocks before the interrupt request-associatedevent occurs in which the NNU 121 writes the result of the last (fourhundredth) execution instance of the loop body to the weight RAM 124.This is because when the loop count 4914 equals 50 (i.e., which is whenthe control logic 4702 generates the interrupt request 4712), then theNNU 121 typically will spend 12 clocks for each of the remaining loopexecution instances, for a total of approximately 600 clocks.

An advantage of the embodiments described is that they give theprogrammer the ability to be as precise as possible about the number ofclocks before an NNU 121 interrupt request-associated event occurs thatthe NNU 121 generates the interrupt request. This is particularlyadvantageous given the fact that: (1) a single NNU 121 instruction maytake thousands of clocks to complete (e.g., with a large repeat count),and (2) an NNU 121 program may have a loop with a relatively large loopcount, yet one interrupt request needs to be generated while the programis looping, i.e., the interrupt request needs to be generated at aparticular iteration of the loop (i.e., before all the looping iscomplete), and in some cases at a certain point within the loop on theparticular iteration.

It should be understood that in some cases the interrupt condition maybe set such that the NNU 121 interrupts the core 4002 “too early.” Thatis, the event associated with the interrupt request may not haveoccurred by the end of the interrupt latency. (Nevertheless, theoperating system (e.g., device driver) may still perform correctoperation by reading the status register 127 of the NNU 121 to determinethat the event has occurred before proceeding. As described above, theNNU 121 includes status registers 127 that the core 4002 can read todetermine the state of the NNU 121, e.g., whether the event associatedwith the interrupt request has occurred.) This may result in some amountof inefficiency of utilization of the core 4002. Thus, advantageously,the programmer is enabled to customize the interrupt condition to tailorthe amount of time before the interrupt request-associated event thatthe NNU 121 generates the interrupt request 4712 based upon whether itis more critical to reduce wasted utilization of the NNU 121 or of thecore 4002. That is, the programmer may cause the NNU 121 to generate theinterrupt request 4712 a number of clock cycles before the interruptrequest-associated event that is less than the interrupt latency of thecore 4002/operating system if core 4002 is considered the more criticalresource; whereas, conversely the programmer may cause the NNU 121 togenerate the interrupt request 4712 a number of clock cycles before theinterrupt request-associated event that is more than the interruptlatency of the NNU 121 if NNU 121 is considered the more criticalresource. Another advantage is that it may increase the productivity ofthe programmer that develops the program that runs on the NNU 121.

Although embodiments have been described in which the apparatus thatgenerates the interrupt request upon condition is a neural network unit,in other embodiments the apparatus may be other programmable devicescapable of executing a program. For example, embodiments in which theapparatus is an encryption/decryption unit, a compression/decompressionunit, a multimedia encoder/decoder unit, a database indexing unit or agraphics processing unit are contemplated.

While various embodiments of the present invention have been describedherein, they have been presented by way of example, and not limitation.It will be apparent to persons skilled in the relevant computer artsthat various changes in form and detail can be made therein withoutdeparting from the scope of the invention. For example, software canenable, for example, the function, fabrication, modeling, simulation,description and/or testing of the apparatus and methods describedherein. This can be accomplished using general programming languages(e.g., C, C++), hardware description languages (HDL) including VerilogHDL, VHDL, and so on, or other available programs. Such software can bedisposed in any known computer usable medium such as magnetic tape,semiconductor, magnetic disk, or optical disc (e.g., CD-ROM, DVD-ROM,etc.), a network, wire line or another communications medium.Embodiments of the apparatus and method described herein may be includedin a semiconductor intellectual property core, such as a processor core(e.g., embodied, or specified, in a HDL) and transformed to hardware inthe production of integrated circuits. Additionally, the apparatus andmethods described herein may be embodied as a combination of hardwareand software. Thus, the present invention should not be limited by anyof the exemplary embodiments described herein, but should be definedonly in accordance with the following claims and their equivalents.Specifically, the present invention may be implemented within aprocessor device that may be used in a general-purpose computer.Finally, those skilled in the art should appreciate that they canreadily use the disclosed conception and specific embodiments as a basisfor designing or modifying other structures for carrying out the samepurposes of the present invention without departing from the scope ofthe invention as defined by the appended claims.

What is claimed is:
 1. A method for operating an apparatus that includesa program memory that holds instructions of a program fetched andexecuted by the apparatus, a data memory that holds data processed bythe instructions, a status register that holds a status that theapparatus updates during its operation, wherein the status has fieldscomprising: a program memory address at which a most recent instructionis fetched from the program memory, a data memory access address atwhich data has most recently been accessed in the data memory by theapparatus and a repeat count that indicates a number of times anoperation specified in a current program instruction remains to beperformed, the apparatus further including a condition register havingcondition fields corresponding to the status fields held in the statusregister, the method comprising: writing, by an instruction of theprogram, the condition register with a condition comprising one or moreof the condition fields; and generating an interrupt request to aprocessing core in response to detecting that the status held in thestatus register satisfies the condition specified in the conditionregister.
 2. The method of claim 1, further comprising: wherein each ofthe condition fields has a corresponding valid bit; and wherein thestatus held in the status register satisfies the condition specified inthe condition register when, for each condition field of the conditionregister whose valid indicator is set, a value of the condition fieldmatches a value of its corresponding status field in the statusregister.
 3. The method of claim 1, further comprising: the statusfurther having fields comprising: a loop count that indicates a numberof times a loop of the program remains to be executed.
 4. The method ofclaim 1, further comprising: wherein the apparatus also includes aweight memory that holds weights associated with neural networkcomputations; the status further having fields comprising: a weightmemory access address at which weights have most recently been accessedin the weight memory by the apparatus.
 5. The method of claim 4, furthercomprising: wherein the weight memory access address comprises both: aweight memory read address at which weights have most recently been readfrom the weight memory by the apparatus; and a weight memory writeaddress at which weights have most recently been written to the weightmemory by the apparatus.
 6. The method of claim 1, further comprising:wherein the apparatus comprises a neural network unit that acceleratescomputations associated with neural networks.
 7. The method of claim 1,the apparatus further comprising: a ring stop that couples the apparatusto a ring bus to which the processing core is also coupled.
 8. Themethod of claim 1, further comprising: wherein the data memory accessaddress comprises both: a data memory read address at which data hasmost recently been read from the data memory by the apparatus; and adata memory write address at which data has most recently been writtento the data memory by the apparatus.
 9. A computer program productencoded in at least one non-transitory computer usable medium for usewith a computing device, the computer program product comprising:computer usable program code embodied in said medium, for specifying anapparatus, the computer usable program code comprising: first programcode for specifying an output for generating an interrupt request to aprocessing core coupled to the apparatus; second program code forspecifying a program memory that holds instructions of a program fetchedand executed by the apparatus; third program code for specifying a datamemory that holds data processed by the instructions; fourth programcode for specifying a status register that holds a status that theapparatus updates during its operation, the status having fieldscomprising: a program memory address at which a most recent instructionis fetched from the program memory; a data memory access address atwhich data has most recently been accessed in the data memory by theapparatus; and a repeat count that indicates a number of times anoperation specified in a current program instruction remains to beperformed; fifth program code for specifying a condition register havingcondition fields corresponding to the status fields held in the statusregister; wherein the condition register is writeable, by an instructionof the program, with a condition comprising one or more of the conditionfields; and sixth program code for specifying control logic thatgenerates on the output an interrupt request to the processing core inresponse to detecting that the status held in the status registersatisfies the condition specified in the condition register.
 10. Thecomputer program product of claim 9, the status further having fieldscomprising: a loop count that indicates a number of times a loop of theprogram remains to be executed.
 11. The computer program product ofclaim 9, wherein the computer usable program code further comprising:seventh program code for specifying a weight memory that holds weightsassociated with neural network computations; the status further havingfields comprising: a weight memory access address at which weights havemost recently been accessed in the weight memory by the apparatus. 12.The computer program product of claim 9, wherein the at least onenon-transitory computer usable medium is selected from the set of adisk, tape, or other magnetic, optical, or electronic storage medium.